Simple syntax:
-lt, -gt, ... are options of test command, look shell builtin test (= also [ ] )
After while is some command line, shell will do it, check exit code and if it's 0 = okay, then do the command lines between do and done.
while true
while cp x y
while (( i < 100 ))
while [ "$some" -lt 100 ]
while test "$some -lt 100
while [ "$some" = "1" ]
while read line
while :
...
: is command, which is builtin and give always exit 0 status ( shell's nop command), do nothing. Today also true and false are builtin commands, so those are more "readable" as :
You can break the loop using command break.
You can jump to the while line using command continue.
ex.
I like to “optimize” / make more like a real program my bash script by replacing repetitious code which utilizes positional parameters.
I am having two issues I cannot solve and would appreciate some assistance with resolving them.
a) how to modify the whiptail checklist... (3 Replies)
I have a shell script which has this while loop line
"while read tblName xx; do..."
I understand how while loop works but don't know what does this xx stands for? (1 Reply)
I am using simple for loop, but getting syntax error when I run the code
code
#!/bin/ksh
pls enter number
read n
for(i=1; i<=n; i++)
do
echo $i
done
syntax error
+ pls enter number
+ read n (5 Replies)
I am trying to run a menu option though IF loops. I keep getting errors not allowed the menu to be processed correctly. Currently it will accept the first 2 statements but then crash on the 3rd. The 2nd and 3rd have the same syntax, so I do not understand why it breaks.
#!/bin/bash
while... (4 Replies)
hi,
I have to use for loop in my script. The below code is providing an output,
1,2,3,4,5..n. But i need to display the values one by one eg: it has to display the first value then exit from the loop and display the second value then exit till n(last value).
for i in 1,2,3,4,5..n
do ... (2 Replies)
I'd like a shell-script syntax checker that can detect at least the following errors, and more:
1. Variable $VAR used but VAR has not been defined.
2. Variable VAR defined but never used.
3. Use of unquoted variables which might break external commands e.g. SOMETHING in: value=`grep $SOMETHING... (5 Replies)
Hi guys,
I'm trying to loop through a number of files that is set by whatever is in a field.
eg.
The idea is to split FILELIST down into fields, it could contain 1 - 999 fields and it's bar delimited.
I thought simple, count the number of fields in the field and then loop... (1 Reply)
Hi,
I have the following script (compile_mercury) and I get this error: I have no idea why...and I have written this script completely in linux (bash) and not in windows.
****************
./compile_mercury: line 136: syntax error near unexpected token `done'
./compile_mercury: line 136:... (1 Reply)
i don't get what's wrong here. i'm writing a shell script that takes 1 argument (a number) from the command-line, but it's throwing an error:
Syntax error: Bad for loop variable
doesn't make much sense
for (( i = 1; i = ${1}; i++ )) # error points to this line everytime
do
echo... (9 Replies)