Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Loop in *.sh

Status
Not open for further replies.

saw15

Technical User
Jan 24, 2001
468
US
Trying to use the following loop (from previous example) in a *.sh script.

for file in 'ls'; do
compress $FILE
done

Question is this, the *.sh file contains a variable exppath that defines the path to the data files. This *.sh is called from the scripts directory.

Do I need to include the path or variable defining the path to the datafiles within the for loop? Where would I include such?

for file in exppath 'ls'; do
compress $FILE
done

or

for file in 'ls' exppath; do
compress $FILE
done

Help is much appreciated.
 
Try this:

Code:
for file in `ls $exppath`
do
  compress $FILE
done

or this:

Code:
cd $exppath
for file in `ls`
do
  compress $FILE
done

or this:

Code:
compress -f $exppath/*
 
Hi
I don't know which .sh you are talking and what does this exppath is but I am guessing that you want to copress every file in particular dir.

#/bin/sh
cd /source_dir

for i in `ls | sed 's/\s+/ /g'`
do
echo $i
compress ${i}

done

Patel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top