Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu' -DCONF_VENDO$
uname output: Linux system-x 4.2.0-19-generic #23-Ubuntu SMP Wed Nov 11 11:39:30 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
Bash Version: 4.3
Patch Level: 42
Release Status: release
Description:
If clicking on a functioning command line script from a filemanager gui and selecting 'run in terminal' , substring expansions will fail in multiple versions of Debian.
Repeat-By:
#!/bin/bash
# Set of tests to show how Substring Expansion causes failure when script is run via the filemanager GUI icon
# but succeeds when run directly from the CLI or if using cut as an alternative method.
# Succeeds, no problem with Fedora/Gnome 22 live ...
# Also works with Knoppix 7, with Xterm from both PCManFM and Dolphin (Konsole is stable but runs nothing from the gui)
# Fails with Ubuntu, both Unity & OpenBox, both Nautilus and PCManFM, 15.10 (full install) Both Xterm & Gnome Term
# Plus Unity/Nautilus on 14.04 live, 12.10 live & 12.04LTS installed
# Fails with KDE Kubuntu 15.10 live, Konsole crashes the filemanager (dolphin) Xterm needs install but again fails with the substrings
# Fails Debian with Kernel 4.0.0-1 on Gnome Gparted rescue CD with fluxbox & PCManFM
# Also with Debian 8.2 live stable with Gnome & Nautilus, on Kernel 3.16.7 ('open-with' xterm not available)
printf "\033c" # clear
StringTest="meaningfulwords"
echo; echo " A brief snooze zzz.... could crash if run via Debian/Ubuntu filemanager... "; sleep 3
# comment out the next two lines to get this script to work when started from certain file manager GUI
echo; echo " Test1: ${StringTest:0:4}" # works CLI only, fails from the GUI
echo; echo " Test3: ${StringTest: -5} " # fails from the GUI
#
echo; echo " Test2: ${#StringTest} " # works for both
echo ; echo $StringTest | cut -c 1,2,3,4 # works
Text1=$( echo $StringTest | cut -c 1,2,3,4 ) # works
Text2=$( echo $StringTest | cut -c 4-6 ) # works & all below
echo; echo " text1: $Text1 "
echo; echo " text1b: $( echo $StringTest | cut -c 1,2,3,4 ) "
echo; echo " text2: $Text2 "
echo; echo " Longer snooze to hold a gui launched terminal open" ; echo; sleep 10
Fix:
This doesn't happen with Fedora.