All Questions
15 questions
7
votes
4
answers
14k
views
Bash for loop with string var containing spaces
In my directory I have two files with space, foo bar and another file. I also have two files without space, file1 and file2.
The following script works:
for f in foo\ bar another\ file; do file "$...
1
vote
1
answer
2k
views
A variable inside an another variable
I have these variables
a1=0.017
a2=0.2
a3=10.7
a4=20.9
a5=35.4
for ((x=1; x<=5; x++))
do
for i in a${x}
do
echo "Welcome $i times"
done
done
The output must be:
"Welcome 0.017 ...
0
votes
1
answer
186
views
Bash array arent adding elements to last
root@kali-linux:~/Softwares/Softwares/Tools/dirsearch# array=()
root@kali-linux:~/Softwares/Softwares/Tools/dirsearch# for i in 1 2 3 4
> do
> array+=($i)
> done
root@kali-linux:~/Softwares/...
-1
votes
1
answer
321
views
Why does this for loop ignore my variable? [duplicate]
I am trying to do a simple script which runs a few commands N number of times, determined by the user's input. However, when it comes to run the commands (in a for loop) - The variable is ignored:
...
1
vote
1
answer
536
views
The $@ variable is not working in a for loop, trying to iterate through a users list
PROBLEM:
I can't get the $@ variable to do what I want in a for loop, the loop only sends one name into the file while looping, it should loop through all the arguments and write them to the file ...
2
votes
2
answers
126
views
Default variables in Bash
The default variable for loops in Perl is $_. Is there any equivalent of this in Bash?
0
votes
2
answers
2k
views
Variable not incrementing in for loop
I am trying to print the number of directories in the working directory. For some reason my counter is not incrementing. Can you please tell me why?
#!/bin/bash
n=0
for afile in $(ls)
do
if [ -d $...
7
votes
2
answers
20k
views
How to convert an input parameter to integer value in a for loop in bash? [duplicate]
in my bash script I try to use a number as an input variable for a for loop
I run the script as
./script.sh InputFolder/ Number_of_iterations
the script should work inside the given folder and run a ...
-3
votes
1
answer
562
views
How to pass an argument to a Bash script variable without a for loop?
I have the following script I use to make webapp conf files (under /etc/nginx/sites-available/).
This is the script:
#!/bin/sh
for domain; do
cat <<-WEBAPPCONF > /etc/nginx/sites-...
0
votes
2
answers
925
views
Bash: One argument per one undefined variable
Say I create a file ~/myScript.sh:
#!/bin/sh
for myVar; do
echo "Hi"
done
If I execute bash myScript with no arguments I'll get nothing but if I'll execute it with one or more arguments I'll get ...
7
votes
1
answer
2k
views
Shell variables in a for loop
I have a difficulty getting over this man bash passage.
If the control variable in a for loop has the nameref attribute, the list of words can be a list of shell variables, and a name reference will ...
1
vote
1
answer
113
views
Storing the each output into a variable
I have script here that will list the date that the user will enter and output the date 5 days ago.
#!/bin/bash
echo "What month?"
echo "1 - January"
echo "2 - February"
...
1
vote
1
answer
299
views
Func name as variable in loop
Overview:
I save my variable in a config file and call them later.
Each entry with the name FailOverVM has a number beside it like FailOverVM1 and I want to check to see if it has data and generate a ...
0
votes
1
answer
68
views
How to grouped the following variable and command and read 1 by 1
I've following array and variable :
httpurl="http://www.nnin.com"
firstquery=$(curl -s -X POST -d "UID=user1&PWD=1111" $httpurl)
name="firstcust"
ip="105.105.0.1"
httpurl="http://www.mmim.com"
...
1
vote
0
answers
2k
views
passing variable through cat EOF command with for loop
How do I get the script run with the sbatch command to run with the 23 individual run_prep_chem_$dd.sh (i.e. run_prep_chem_08.sh...run_prep_chem_30.sh)? I am thinking since its in this for loop that ...