BASH: instad of echo-ing, I just want to assing to a bash variable... how??
Hi Guys
Given this bash fragment: Code:
filename="${base%.*}" E. g. this does NOT work: Code:
filename="${base%.*}" It feels as if I must escape something somehow, to keep the code from being "triggered" even if being assigned to a variable? |
Use command substitution. Better with the $(...) syntax, unless you want your code be portable to the Bourne Shell.
|
Thanks... I already have... it is why I posted...
I have tried Code:
ext="`${file_base%}|awk -F . '{print $NF}'`" [rylan@development ~]$ prozget.sh http://www.google.com.abc.def/tzaneen.xls xls tzaneen ./prozget.sh: line 8: ./tzaneen.xls: Permission denied where line 8 is the above line of code... How do I substitute correctly? The link you sent stipulated `` as command substitution characters. Thanks! Any other ideas how to assign the output to a variable? |
If I try
Code:
ext=$("${file_base%}|awk -F . '{print $NF}'") Quote:
Quote:
Ye gods... I just want that to go into a variable... not go to the moon...! :) |
Code:
ext=`echo ${base%}|awk -F . '{print $NF}'` |
Quote:
Quote:
Code:
varname=$(command) Code:
${file_base%}|awk -F . '{print $NF}' Code:
echo ${file_base%}|awk -F . '{print $NF}' Code:
my_var=$(echo ${file_base%}|awk -F . '{print $NF}') |
Hi Dive, Colucix
This Quote:
e. g. Code:
[rylan@development ~]$ prozget.sh http://www.google.com.abc.def/tzaneen.xls Code:
echo ${file_base%}|awk -F . '{print $NF}' Code:
ext=`echo ${base%}|awk -F . '{print $NF}'` Code:
ext="`echo ${base%}|awk -F . '{print $NF}'`" Thanks for the help anyway... I had no idea this was so incredibly tough to do! |
Dive and Colucix
Thanks... [high embarrassment factor] I had my variable reference wrong Dive... your suggestion worked. Thanks Colucix! If you remove the idiot from the equation, your suggestions worked fine... [/high embarrassment factor] THANK YOU!! |
Ok. Let's start from the beginning. You launch a script (prozget.sh) and pass a URL as argument. What do you want to put exactly inside the ext variable?
EDIT: Ok... didn't see your last message before posting. There is no idiot in the equation, just some hurry! ;) |
Ok but thanks again anyway.
The whole idea of the script is to eventually call the prozilla downloader binary. The script first checks if the file you will download already exists in the directory you are calling the script in. If it is, it fudges the name of the file and renames it to the fudged name, THEN calls prozilla on the download. E. g. you will most likely not accidentally overwrite a file with a name that is the same of the file you are prozilla'ing down off some server somewhere. Here's my final script, and it works - thanks to you guys' help! Call with, for example, Quote:
Code:
filename="$1" |
All times are GMT -5. The time now is 10:06 PM. |