The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
whats wrong with this code nadman123 Shell Programming and Scripting 4 04-15-2008 05:42 PM
tell me whats wrong with this nadman123 Shell Programming and Scripting 1 04-14-2008 08:58 PM
tell me whats wrong in this? nadman123 Shell Programming and Scripting 1 04-09-2008 10:11 PM
Whats wrong with this script? kayarsenal Shell Programming and Scripting 2 08-25-2006 06:58 AM
whats wrong with this awk??? george_ Shell Programming and Scripting 5 04-04-2006 01:58 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-02-2006
Registered User
 

Join Date: Jan 2006
Location: Sweden
Posts: 42
Thumbs up Whats wrong with my function?? <newbie>

First of all im using Bash, on a Debian-based machine. I tried to write a function that if the ls program found listed more than 25 lines I would automaticly use "ls | less". Its on another computer but if I recall it looked something like this...

Note: some code may look strange because im on this stupid spanish keyboard where nothing does as it says...

Quote:
master_ls() {
if [ "$(ls -F)" -gt "25" ]
then
ls - F | less
else
ls - F
}
I tried assigning it to "ls" with the effect of (i think) infinite recursion.
System crashed...
Also tried assigning it to "lss" with the SAME problem (i think).
System crashed...

In despair i just tried to create an alias like:

alias lss="ls -F | less"

which only worked in the current directory..

also tried: lss="ls -F $@ | less" and lss="ls -F ${@:-$(pwd)}"

Have no idea what to do...

Regards
Richard
Reply With Quote
Forum Sponsor
  #2  
Old 03-02-2006
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,249
You can't pass parameters to an alias that uses a pipe, so perhaps use a shell function instead. A function does not need an alias since you can just invoke it directly. Also, take a look at the manual pages for less. You might find that there is an option to quit if one screen.
Reply With Quote
  #3  
Old 03-03-2006
Registered User
 

Join Date: Feb 2006
Location: Southern England
Posts: 102
Thumbs down

Code:
ls()
{
   /usr/bin/ls
}
i wouldn't recommend it though
Reply With Quote
  #4  
Old 03-03-2006
Registered User
 

Join Date: Feb 2006
Location: Southern England
Posts: 102
ls | more

will work how you want
Reply With Quote
  #5  
Old 03-04-2006
Registered User
 

Join Date: Jan 2006
Location: Sweden
Posts: 42
well the thing is that i want it to be automatic.. So i dont have to type a command TWICE when the screen gets filled... Thanks for your interest anyway...
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:46 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0