Computing.Net > Forums > Linux > simple bash script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

simple bash script

Reply to Message Icon

Name: _Samer_
Date: January 17, 2003 at 22:48:27 Pacific
OS: RH 8.0
CPU/Ram: Celeron 500/256 RAM
Comment:

A bash script that would scroll through the files in a particular directory (an arbitrary number of files, with arbitrary names, in a specified directory) would be very useful.

If someone knows how to achieve this, I would certainly appreciate your enlightenment.

Thanks,
Samer



Sponsored Link
Ads by Google

Response Number 1
Name: Danny Larouche
Date: January 17, 2003 at 23:40:07 Pacific
Reply:

It will be easier to do in perl script than bash due to need for random and array.


0

Response Number 2
Name: Don Arnett
Date: January 18, 2003 at 08:17:47 Pacific
Reply:

Random?? Array?? Where does that come from? We must be reading different descriptions.


'scroll through' - what do you mean my that. I imagine that you don't mean just list the files, because that can be done with 'ls'. So, maybe you mean to display the contents of each file:

# change to the desired directory (dir name is first command line parameter)
cd $1

# loop thru each file in the directory
for file in `ls`
do

# display the file contents
more $file

done

# change back to original directory
cd -


Make sure that you use back quotes around the ls command above


0

Response Number 3
Name: _Samer_
Date: January 18, 2003 at 11:47:43 Pacific
Reply:

Thanks for the help. What I meant was, there are many times when one wants to do certain things, the same things to files in a directory, regardless of the names of the files, and how many files are in that directory, thats all.


0

Response Number 4
Name: Danny Larouche
Date: January 19, 2003 at 11:36:55 Pacific
Reply:

find /dir -exec /bin/command {} \;


0

Response Number 5
Name: Don Andrews
Date: January 20, 2003 at 10:56:47 Pacific
Reply:

Look in the Bash programmin HOW-TO, section 7.1 (http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-7.html#ss7.1) change "echo item: $i" to whatever you need. If you are installing a bunch of RPMs it would be rpm -Uvh $i, whatever. Bash interprets anything inside parentheses as a command. The cool thing is you can do this all on the command line, no need to write a script unless you do the same thing over and over.


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Linux Forum Home


Sponsored links

Ads by Google


Results for: simple bash script

How logout from login-menu bash script? www.computing.net/answers/linux/how-logout-from-loginmenu-bash-script/9016.html

Separating commands in bash scripts www.computing.net/answers/linux/separating-commands-in-bash-scripts/20341.html

Writing a small bash script. www.computing.net/answers/linux/writing-a-small-bash-script/17165.html