If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > getting started:a simple ls program

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-22-04, 23:24
rei rei is offline
Registered User
 
Join Date: Jul 2004
Posts: 30
Unhappy getting started:a simple ls program

i'm just getting started with shell programming.

to start with, i tried to write a script which shows the result of ls.

Code:
#! /usr/local/bin/bash

echo "beginning of ls"

`ls -l `

echo "end of ls"

exit 0
It returns
beginning of ls
./test.sh: total: command not found
end of ls

It is because "total" was outputed from "ls -l"

Thus i changed my code to `ls -l` 2>/dev/null

Although i get no errors, i get no result of "ls -l" too..
just a simple of:
beginning of ls
./test.sh: total: command not found
end of ls

How can i execute "ls -l", at the same time displaying the result on screen, without asking the shell to execute lines displayed on screen (for example : total)

Thanks
Reply With Quote
  #2 (permalink)  
Old 08-22-04, 23:51
rei rei is offline
Registered User
 
Join Date: Jul 2004
Posts: 30
changed my code to the following

Code:
LIST=`ls -l`
echo $LIST
It works, but without newline.
Any other ways to implement it?

Thanks
Reply With Quote
  #3 (permalink)  
Old 08-23-04, 05:02
SiverSloth SiverSloth is offline
Registered User
 
Join Date: Jun 2004
Posts: 29
Why the backticks?

backticks are used when you want to put the output of a command into a variable. If you just want the output on stdout (the screen) use
Code:
#! /usr/local/bin/bash

echo "beginning of ls"

ls -l 

echo "end of ls"

exit 0
Reply With Quote
  #4 (permalink)  
Old 08-23-04, 08:27
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
...and in your original 'echo $LIST' attempt, you could have quoted $LIST to retain the whitespace/newlines. e.g. echo "$LIST"
Reply With Quote
  #5 (permalink)  
Old 08-24-04, 01:58
rei rei is offline
Registered User
 
Join Date: Jul 2004
Posts: 30
Quote:
Originally Posted by Damian Ibbotson
...and in your original 'echo $LIST' attempt, you could have quoted $LIST to retain the whitespace/newlines. e.g. echo "$LIST"
Thanks very much damian!!!
I've grown up a bit from your guidance!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On