karlp
November 18, 2009, 12:41pm
1
Well, I think I've managed to take two different issues and conglomerate them into and embarrasing mess.
#!/bin/bash
# Set some variables
dir1=/path/that/isnt/variable/$variabledir/dir/
dir2=/path/that/isnt/variable/$variabledir/important/"$variabledir"-subdirectory/path/
echo "Gimme input, a whole lotta input"
echo ""
read variabledir
echo "Your input is: $variabledir"
echo $dir1
echo $dir2
#
exit 0
Why is this not working? Or, why is it working, and just not as expected? Reading throws me a null value for variabledir.
TIA!
karlp:
Well, I think I've managed to take two different issues and conglomerate them into and embarrasing mess.
#!/bin/bash
# Set some variables
dir1=/path/that/isnt/variable/$variabledir/dir/
dir2=/path/that/isnt/variable/$variabledir/important/"$variabledir"-subdirectory/path/
$dir1 and $dir2 will contain whatever the value of $variabledir is at the moment of assignment.
echo "Gimme input, a whole lotta input"
echo ""
read variabledir
echo "Your input is: $variabledir"
echo $dir1
echo $dir2
#
exit 0
Why is this not working? Or, why is it working, and just not as expected? Reading throws me a null value for variabledir.
#!/bin/bash
# Set some variables
dir1=/path/that/isnt/variable/\$variabledir/dir/
dir2=/path/that/isnt/variable/\$variabledir/important/\$variabledir-subdirectory/path/
echo "Gimme input, a whole lotta input"
echo ""
read variabledir
echo "Your input is: $variabledir"
eval "echo $dir1;echo $dir2"
#
exit 0
karlp
November 18, 2009, 1:18pm
3
So, thanks, two questions...
1: The slashes prior to the dollar sign in dir1 and dir2, are those there for a reason?
2: Will removing the quotes from dir2's use of variabledir cause the -subdirectory to be appended, or would it be treated as a full and new variable with a dash in the name?
EDIT: 2 is not an issue, and I'm not sure why the slashes helped, but they did. Thanks a bunch!
karlp:
So, thanks, two questions...
1: The slashes prior to the dollar sign in dir1 and dir2, are those there for a reason?
The slashes preserve the dollar signs as literal dollar signs.
The quotes don't do anything, so removing them doesn't affect anything.
(Quotes are only necessary in a variable assignment to preserve literal whitespace.)
karlp
November 18, 2009, 1:43pm
5
Thanks for the quick reply...
This is in fact a piece of a script for processing files associated with a particular application, and part of the script uses unzip to process files according to these variables.
unzip -n $dir2/$variabledir.zip
And I keep getting half of the string.
unzip: cannot find or open /path/that/isnt/variable/$variabledir/dir/\$variabledir-subdirectory/path/$variabledir.zip
eval "dir1=$dir1"
eval "dir2=$dir2"
dir1=/path/that/isnt/variable/${variabledir}/dir/
dir2=/path/that/isnt/variable/$variabledir/important/${variabledir}-subdirectory/path/
The braces don't do anything. That is exactly the same as:
dir1=/path/that/isnt/variable/$variabledir/dir/
dir2=/path/that/isnt/variable/$variabledir/important/$variabledir-subdirectory/path/