Shell script for loop syntax
Brace expansion, {x..y} is performed before other expansions, so you cannot use that for variable length sequences.
Instead, use the seq 2 $max
method as user mob stated.
So, for your example it would be:
max=10
for i in `seq 2 $max`
do
echo "$i"
done
syntax of for loop in linux shell scripting
You probably run it with sh
, not bash
. Try bash test1.sh
, or ./test1.sh
if it's executable, but not sh test1.sh
.
How do I write a 'for' loop in Bash?
From this site:
for i in $(seq 1 10);
do
echo $i
done
Nested for loop in unix shell script
You can't loop over an index+value pair directly in Bash. I would write this code as follows:
index=0
for path in /optware/oracle/logs/20190311_JAVA/TEMP/*
do
echo " <tr>${index}<td></td><td>${path}</td></tr>" >> Temp.lst
((++index))
done
How do I iterate over a range of numbers defined by variables in Bash?
for i in $(seq 1 $END); do echo $i; done
edit: I prefer seq
over the other methods because I can actually remember it ;)
Related Topics
How to Mount a Remote Linux Folder in Windows Through Ssh
What Happens When You Run a Program
Remove Line of Text from Multiple Files in Linux
How to Find Out What Group a Given User Has
Postgresql Database Default Location on Linux
How to Udp Broadcast with C in Linux
How Can the Linux Kernel Be Forced to Enumerate the Pci-E Bus
Run Bash Command on Jenkins Pipeline
Randomly Pick Lines from a File Without Slurping It with Unix
What Are Stalled-Cycles-Frontend and Stalled-Cycles-Backend in 'Perf Stat' Result
Attaching and Mounting Existing Ebs Volume to Ec2 Instance Filesystem Issue
How to Wait for Server Restart Using Ansible
Installing R from Cran Ubuntu Repository: No Public Key Error
Error with Gradlew: /Usr/Bin/Env: Bash: No Such File or Directory
Getting Error on Supervison on Supervisorctl Error (No Such Process)
How to Create a File in Linux from Terminal Window
Weird Sigsegv Segmentation Fault in Std::String::Assign() Method from Libstdc++.So.6