I'm writing a shell script using #!/bin/bash instead of #!/bin/sh because of the substitution: ${!variable}, which won't work with sh. My main problem is the following (just a summarized example, the script is much more complex):
Thank you!
---------- Post updated at 02:00 PM ---------- Previous update was at 12:32 PM ----------
At least someone to tell me the POSIX alternative for ${!variable}, please:
Last edited by teresaejunior; 08-28-2010 at 02:12 PM..
Reason: You could paste this now in a terminal
This, in my opinion, is one of the serious shortcomings of bash. When piping the output of a command to a while loop, the contents of the while are executed in a forked process and thus variables that are local to the script, and should logically be updated as a part of the loop, are not.
I'd run your script using ksh (#!/usr/bin/env ksh) provided it is installed on your host.
Small example to illustrate:
Running the script (t22) with bash vs ksh:
Ksh does it right, the variable var is updated in the while as expected. Ksh also supports the ${!name} construct you are looking for.
This is helpful, thanks! Though some parts of my script won't work in ksh. But, now I can redirect the loop output to a temp file and source it. Should be enough.
Just an addition, there could be some smarter way to say:
I would be very interested in knowing what doesn't work under Ksh.
Quote:
Just an addition, there could be some smarter way to say:
Something like:
Im not sure what your goal is with this, but this might work.
Causes a double evaluation of the statement. $number will be expanded, and then the ${...} will be expanded.
It's a set of scripts which are going to be packaged together, they're almost ready, so I would have to check the functionality of them all under another interpreter. From this script:
In bash it runs the application, in ksh it redirects the output to the file ?Ê.
Last edited by teresaejunior; 08-28-2010 at 04:00 PM..
This User Gave Thanks to teresaejunior For This Post:
It's a set of scripts which are going to be packaged together, they're almost ready, so I would have to check the functionality of them all under another interpreter.
I certainly understand that -- glad you could work round the issue in bash.
Quote:
In bash it runs the application, in ksh it redirects the output to the file ?Ê.
Just for the future, that can be done in ksh, though it is a completely different syntax all together:
Then use the read/write commands to read/write from/to the application. It's also possible to map the pipe to stdin/out.
OK, I'm striving to abide by all the rules this time.
Here is a fragment of my windows10/cygwin64/bash script:
export BUPLOG=$(BackupRecords --log "$src")
robocopy $(BackupRecords -mrbd "$src" --path "$src") $(BackupRecords --appSwitches "$src") "$src" "$dst" $(BackupRecords --fileSwitches... (15 Replies)
OK, I'm striving to abide by all the rules this time.
Here is a fragment of my windows10/cygwin64/bash script:
export BUPLOG=$(BackupRecords --log "$src")
robocopy $(BackupRecords -mrbd "$src" --path "$src") $(BackupRecords --appSwitches "$src") "$src" "$dst" $(BackupRecords --fileSwitches... (0 Replies)
Hi
I am setting the variables like this :
setenv MODULE1 modem5__3
setenv MODULE2 modem5__2
setenv MODULE3 modem_ctrl_1_1
setenv MODULE4 modem_1_0
setenv COUNT 10
I am having a bash script as shown below
################################################
#!/bin/bash
for ((... (5 Replies)
I have one script calling another with a set of strings that includes white space. Script A calls Script B with these input strings: one two "th ree"
Script B pulls apart the arguments correctly:
arg0 = one, arg1 = two, arg2 = "th ree"
if I call it from within Script A like so:... (10 Replies)
Hi,
I need to embed a metatag to image files which contain qrcodes, i usually do this with exiv -M "set Exif.Image.DocumentName `zbarimg -q -Sdisable -Sqrcode.enable --raw image.tif`" image.tif
which works fine. However I need to do this recursivly for whole directory and subdiretory... (4 Replies)
Hi all.
I'm trying to finish a bash script with the following elements:
ARRAY="blah $ITEM blah blah"
ARRAY="blah blah $ITEM blah bluh"
#ARRAY="...."
# ...the ARRAY elements represent a variable but defined
# syntax and they're all hard-coded in the script.
#(...)
ITEMS='1.0 2.3... (2 Replies)
Is it possible with a bash variable to perform multiple substitution strings to one variable?
I have this variable:
echo $clock
TIMEZONE="US/Central"
What I would like to do with bash only it pull out just the "US" part of the variable.. which could be any number of countries.
this is... (6 Replies)
I have this situation in my script (simplified):
A=C
C=10
I need to get number 10 using just A variable.
I tried with :
echo $`echo $A` - but i get $C string (i need number)
Thanks very much for any help! (1 Reply)