Confused about for loop shell script [duplicate] - shell

This question already has answers here:
How do I iterate over a range of numbers defined by variables in Bash?
(20 answers)
How can I compare numbers in Bash?
(10 answers)
How can I add numbers in a Bash script?
(13 answers)
Closed 5 days ago.
I'm trying to make a simple script that copies a game file 10 times, renaming them 1-10 for when the game patches/updates. Otherwise I have to do it manually. I've been editing with sublime script and am not sure on how to debug or what I'm even doing wrong.
#!/bin/bash
wiz=1
mv /home/redking/.local/share/Steam/steamapps/common/Wizard101/Bin/WizardGraphicalClient.exe /home/redking/.local/share/Steam/steamapps/common/Wizard101
for wiz in 1 .. 10
do
if wiz >= 10
then wiz=1
else
wiz+1
cp /home/redking/.local/share/Steam/steamapps/common/Wizard101/WizardGraphicalClient.exe /home/redking/.local/share/Steam/steamapps/common/Wizard101/Bin/$wiz.exe
done

Related

Why won't incrementing work with this bash shell script? [duplicate]

This question already has answers here:
Using a variable in brace expansion range fed to a for loop
(5 answers)
How do I iterate over a range of numbers defined by variables in Bash?
(20 answers)
Closed 11 months ago.
I am trying to make a user input increment however, if I tried a variable in the increment, it does not work. How to make it work?
My script:
#!/bin/bash
input=$(echo "$((2*100))")
for a in {100..$input..100}
#for a in {100..500..100}
do
echo "Increment at $a times"
done
this will return:
"Increment at {100..200..100} times"
Will appreciate any help. Thank you!

Use command line argument in bash script substituted with value from script [duplicate]

This question already has answers here:
Dynamic variable names in Bash
(19 answers)
How to use a variable's value as another variable's name in bash [duplicate]
(6 answers)
Bash - variable variables [duplicate]
(4 answers)
Closed 2 years ago.
I recently started bash scripting and got stuck with a very basic usecase, searched stackoverflow/google but couldn't find a way to achieve what I am trying to do.
I have a script color.sh
#!/bin/bash
Apple="Red"
Orange="Orange"
Banana="Yello"
echo $$1
What I am trying to achieve is print the color of fruit and accept fruit from command line. The output I want is
./color.sh Apple -> Red, but what I get is some random number which I think is process Id.

Trying to run multiple processes in bash only executes one time [duplicate]

This question already has answers here:
Brace expansion with variable? [duplicate]
(6 answers)
how to use variables with brace expansion [duplicate]
(2 answers)
Closed 2 years ago.
I have the following in my bash file:
echo "Spawning $1 processes"
for i in {1..$1}
do
(go run loadgen.go $2 &)
echo "done."
done
However, I can only seem to get my go file to execute once. I know that they're started in the background, but each of my go files should append to the same log file (I can reproduce this by running my bash script multiple times). Am I doing something wrong to get this to iterate multiple times?

Is there any selection function in perl? [duplicate]

This question already has answers here:
How can I loop through files in a directory in Perl? [duplicate]
(3 answers)
How can I build a simple menu in Perl?
(6 answers)
Closed 4 years ago.
In bash script, we know that there is a select function that can list all the files in current directory with number for selection. Once choose the number, can get the value behind.
select application in */; do test -n "$application" && break; echo ">>> Invalid Selection"; done
Is there any similar function in perl?
Thanks

Equivalent of setTimeout in Bash [duplicate]

This question already has answers here:
How to run a process with a timeout in Bash? [duplicate]
(2 answers)
How do I pause my shell script for a second before continuing?
(10 answers)
Closed 5 years ago.
I am new to shell scripting, and would like to know how to call the second script 5 seconds after running the first script. In the example below, I would like ./csv3xlsx_osx to run 5 seconds after the python script completes.
python script.py
./csv2xlsx_osx -infile input.csv -outfile ouptut.xlsx
How would one go about doing the equivalent of Javascript's setTimeout() in shell?

Resources