I have a bash script that has 13 variables and runs commands on them.
I've copied the commands 13 times but I'd like to simplify it to simply add 1 to the previous and run 13 times.
The variables are
dir01=/path/to/dir01
dir01=/path/to/dir02
... up to 13. (more may be added later)
I'd like to simplify it to something like this:
I don't know how to get it to stop when it's done 13 or whatever number of variables I have.
BTW I'm using cp and rm because mv won't clobber a directory.
These are render log files that are annoying and mostly useless so I don't mind overwriting files.
You are already using bash's shell arithmetics, why don't you use it for your loop:
BTW, don't cp and rm without error checking - if th cp fails, your log file is gone; use mv instead.
I defined paths for dir1 through dir13 as variables but I can't get the loop to add the number to the "dir" to create "dir1" and then use it as the defined variable.
This is my test code:
Instead of echoing the defined path for variable "dir1, dir2 ..." it echos "dir1" and "dir2," literally.
If I echo "$dir1" by adding it manually, I get the defined path as desired.
Why won't $dir$num echo as the path?
Variables don't work that way. Dynamic variable names are discouraged in general -- that's the sort of thing you should be using an array or even just a space-separated string for.
You can dereference a variable name with ${!...} however. (This is a BASH-only feature.)
You must assign the complete variable name to a string first, you can't put substitutions directly inside the ${}.
How can I set a variable with a space in it?
"dir 1" and "dir\ 1" don't work.
I'm interested if having spaces in the variable definition would also work.
So, let's say I have a usual batch rename file like this:
and I'd like to have a secon bat file, that can /reverse" the first.
BUT, I don't want to simply "rewrite" it like
move hello 254352426
but rather, have the new script take the source and destination and reverse it somehow... (6 Replies)
In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed ? Is there any way to get the script names for the process command ?
--- Post updated at 08:39 AM ---
in KSH (Korn Shell), my command output shows the script names but when run in the Bash Shell... (3 Replies)
Im looking for 2 Files -> *.WAV and *.wav with
find . -name 'unavail.wav' -o -name 'unavail.WAV' I need to list the Folders that contains these 2 Files?
Thx in advance (13 Replies)
I'm new to utilities like socat and netcat and I'm not clear if they will do what I need.
I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes.
I'm using Cygwin bash on Windows 10.
My... (3 Replies)
So I'm trying to pass certain json elements as env vars and use them later on in a script.
Sample json:
JSON='{
"Element1": "file-123456",
"Element2": "Name, of, company written in, a very weird way",
"Element3": "path/to/some/file.txt",
}'
(part of the) script:
for s... (5 Replies)
# check host value regex='^(||1|2|25)(\.(||1|2|25)){3}$' if ')" != "" ]; then if ]; then echo host $host not found exit 4 fi elif ]; then echo $host is an invalid host address exit 5 fi
espeacailly the top regex part?
---------- Post updated at 06:58 PM ---------- Previous update was... (1 Reply)
hi,
i have a script that runs on bash and would like to run it on a machine that has csh and bash. the default setting on that machine is csh. i dont want to change my code to run it with a csh shell. is there any way i can run the script (written in bash) on this machine? in other words is there... (3 Replies)
Hi All,
I need to pass a variable to perl script from bash script, where in perl i am using if condition. Here is the cmd what i am using in perl
FROM_DATE="06/05/2008"
TO_DATE="07/05/2008"
"perl -ne ' print if ( $_ >="$FROM_DATE" && $_ <= "$TO_DATE" ) ' filename"
filename has... (10 Replies)
Hello all,
Can somebody explain to me how set up a basename and dirname variable to simplify this script. I currently have a 'infile' with the contents of FTTPDataPVC_ & BaaisDSLFeed. I need to add a basename and or dirname variable so that any additions can be made through the infile and not... (1 Reply)
Struggling to add numbers in shell script..
ie.
a=3
b=4
c=$a + $b
echo $c
I thought this should give me 7 - but cannot see what wrong.. should be simple answer eh? (8 Replies)