LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-25-2005, 01:25 PM   #1
abefroman
Senior Member
 
Registered: Feb 2004
Location: Chicago
Distribution: CentOS
Posts: 1,256

Rep: Reputation: 53
Problem with simple shell script for loop


I am trying to list the permissions of public_html for all users in my home directory.

The command I am using is:
for i in `ls`;do `ls -al $ipublic_html`; done

but it is not working and displays the output as follows"
root@server1 [/home]# for i in `ls`;do `ls -al $ipublic_html`; done
-bash: total: command not found
-bash: total: command not found
-bash: total: command not found
-bash: total: command not found
-bash: total: command not found
-bash: total: command not found
-bash: total: command not found
-bash: total: command not found
-bash: total: command not found
-bash: total: command not found
-bash: total: command not found
-bash: total: command not found
-bash: total: command not found
-bash: total: command not found
-bash: total: command not found
-bash: total: command not found
-bash: total: command not found
-bash: total: command not found
-bash: total: command not found
-bash: total: command not found
-bash: total: command not found
-bash: total: command not found

What would the correct command be?

Thanks in advance.

 
Old 10-25-2005, 02:05 PM   #2
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 5,995
Blog Entries: 5

Rep: Reputation: 782Reputation: 782Reputation: 782Reputation: 782Reputation: 782Reputation: 782Reputation: 782
You shouldn't have back ticks (`) around the command following "do". The back ticks tell it to execute the command then use the commands outuput. They are correct following the "in".

Also you need to encapsulte your variable because it is confused. "for i" says for each item call it $i. You then say "$ipublic_html" so it thinks your variable is ipublic_html instead of $i followed by public_html.
To encapsulate it just use the braces as in ${i}public_html.

for i in `ls`;do ls -al ${i}public_html; done

Finally from what you wrote I suspect these are subdirectories you're trying to list. If so you need to put a slash between the variable and the file name - otherwise its looking for a concatenated name (that is ${i}public_html for subdirectory user1 would give you "user1public_html" but you probably want "user1/public_html". The revised syntax would be:

for i in `ls`;do ls -al ${i}/public_html; done
 
Old 10-25-2005, 08:26 PM   #3
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Quote:
I am trying to list the permissions of public_html for all users in my home directory.
Uh - what?!?

Could you please explain a bit better what you're trying to do? We'd be happy to help you script doing it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[c shell] simple for loop saiz66 Programming 1 09-28-2004 07:02 PM
Simple shell script problem? Corallis Linux - Newbie 3 03-21-2004 11:25 PM
a simple shell script Warchief Programming 1 07-31-2003 05:01 AM
Very Simple Shell Script cli_man Linux - Software 5 04-24-2003 10:14 AM
Simple C Shell script is not so simple elconde Programming 2 09-16-2001 11:53 PM


All times are GMT -5. The time now is 05:55 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration