Why is ls output different when run in script ? | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Why is ls output different when run in script ?

UNIX for Dummies Questions & Answers


Tags
ls ksh script, solved

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-20-2013
Dave Allen Dave Allen is offline
Registered User
 
Join Date: Jun 2013
Last Activity: 20 June 2013, 8:59 AM EDT
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
[Solved] Why is ls output different when run in script ?

I am running KSH shell, and use a bunch of aliases common to a group I am in.

One of them is:
Code:
 ls='ls -F'

I don't think that makes a difference to me / my issue.

Anyways, I enter (at command line): ls abc*.* and get several files listed.

I then create a script file (mls), set its perms to 777, and have it simply be one line with ls $1.

I then enter (at command line)
Code:
    mls   abc*.*

and only 1 file is listed.

Why not all that were listed with ls command directly ???

Last edited by vbe; 06-20-2013 at 10:19 AM..
Sponsored Links
    #2  
Old 06-20-2013
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 23 November 2014, 1:15 PM EST
Location: Switzerland - GE
Posts: 5,920
Thanks: 165
Thanked 431 Times in 403 Posts
What OS are you on?
Sponsored Links
    #3  
Old 06-20-2013
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 23 November 2014, 1:15 PM EST
Location: Switzerland - GE
Posts: 5,920
Thanks: 165
Thanked 431 Times in 403 Posts
Your issue is more to do with what ls gets for agrument when is shellscript:

Code:
ls $1

for your script mls will because of $1 get ONLY 1 argument for that is what $1 stands for...

Try: ls $@ ...

TEsted for you:

Code:
ant:/home/vbe $ mls a*.*
a.out                           acroread_print.howto
a_pre_test.txt                  add_char_at_EOL.howto
ezra.log                           add_inshell.howto
about_filespace_occup_in_FS.pb  adobe_install.err
about_ksh.doc                   aix_lsdev_c.lst
about_ttomuch_arg.howto         at_test.out
absolute_relative_tar.howto     
acroread_pb.txt

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Awk script to run a sql and print the output to an output file adept Shell Programming and Scripting 4 06-10-2012 11:40 AM
[Solved] Looking for script running before I run script again brianjb Shell Programming and Scripting 8 04-27-2012 10:32 AM
run shell script under nohup directly [solved] johninweb Shell Programming and Scripting 0 03-15-2012 02:20 AM
Run perl command in script[solved] Lham Shell Programming and Scripting 0 02-11-2012 07:30 AM
[Solved] Output in bash script not captured in variable lifedj Shell Programming and Scripting 4 02-23-2011 07:43 AM



All times are GMT -4. The time now is 07:56 PM.