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
Related
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
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.
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?
This question already has answers here:
How do I parse command line arguments in Bash?
(40 answers)
How to get exact command line string from shell?
(2 answers)
Closed 3 years ago.
Suppose my script.sh could take a number of options and arguments. What is the best way to find out what the script was invoked with (form inside the script)?
For eg., someone called it with script.sh --foo_option bar_arg
Is there a way to echo that exact command they typed from inside the script?
I've tried echo !! which does not work inside a script.
This question already has answers here:
How to use a variable's value as another variable's name in bash [duplicate]
(6 answers)
What does "${!var}" mean in shell script? [duplicate]
(1 answer)
Closed 4 years ago.
I have the following variables
my_country_code="green"
x="country"
echo ${my_$x_code}
bash: ${my_$x_code}: bad substitution
echo should print green as output, but unable to find any technique which will give the correct output
my_x_code="my_${x}_code"
echo ${!my_x_code}