Results 1 to 4 of 4
I'm trying to create a for loop that uses a function to display the directories in my script. questions can I use variables in this or do i have to ...
- 06-28-2007 #1Just Joined!
- Join Date
- Jun 2007
- Posts
- 3
help with for loops and functions
I'm trying to create a for loop that uses a function to display the directories in my script. questions can I use variables in this or do i have to display each directory in my loop. I'm using bash here's an example
#!/bin/bash
lsl () { ls -l ; }
for t in /proc/ /home/bdrumright/ /var/log/ /etc/ /bin/
do
lsl $t
done
output only displays the first directory /proc/ five times in succession, which i thought it would display all 5 directories individually
- 06-28-2007 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Welcome to the forum.
Replace:
with:Code:lsl () { ls -l ; }
RegardsCode:lsl () { ls -l $1 }
- 06-28-2007 #3Just Joined!
- Join Date
- Jun 2007
- Posts
- 3
thanks
I appreciate the help. It looks like this now and works!
#!/bin/bash
lsl () { ls -l $1 ; }
for t in /proc/ /home/bdrumright/ /var/log/ /etc/ /bin/
do
lsl
done
I'll probably be asking alot of questions here, I am a student and I'm hoping for a career in linux. If there is any other places or books I can use to help me plz share..... Thanks again
- 06-28-2007 #4Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
You're welcome. Here you have some useful links:
LinuxCommand.org: Learning the shell.
http://www.tldp.org/LDP/Bash-Beginne...tml/index.html
http://tldp.org/LDP/abs/html
Also to read the posts here, try to solve the problems without seeing the solution, and compare your results with other results. Try to help others here, it's a great challenge and helpful to learn Linux.
Regards


Reply With Quote