user8476799 user8476799 - 9 months ago 106
Bash Question

Bash run script from script using variable

I am trying to run bash script from bash script using variable.

The variable is assigned before from parsed CSV, and when I echo it the path to another script looks ok. When I try to run the script path from the variable it fails.

Assiging the variable (2nd column from csv):

THE_VARIABLE=`echo ${CHOICE[${WHICH}]} | awk -F";" '{print $2}'`

echo $THE_VARIABLE (ok):


Bash debug:

+ echo $'/fake_path/scripts/\r'

However after that when trying to run:

: No such file or directoryripts/

It seems like taking only part of the string in variable(?).

Thanks for help!

Answer Source

The string ends with ASCII character 13 (\x0D or \015 or \r) and not the sequence '\' 'r', with echo the trailing \r can't be seen because echo adds a \n, but appending a # character for example will show at begining of line.

echo "${THE_VARIABLE}#"

to remove the trailing \r:


otherwise it means that input file has dos line ending \r\n, it could be modified with dos2unix.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download