Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
What is the proper syntax for functions in the .kshrc file?
I'm trying to create a function called cdl which cd's into the directory listed after "cdl" then ls's everything inside the directory. In bash, I was able to get it to work using:
function cdl() {
cd $1
ls
}
but this doesn't seem to work in ksh. in ksh, i also tried:
function cdl {
cd $1
ls
}
or something like this, and what it would do is list everything in the directory that was listed after "cdl", but it wouldnt actually go into that directory.
I just tried this in ksh, and it didn't work. I'm having the same problem stated in my first post... "what it would do is list everything in the directory that was listed after "cdl", but it wouldnt actually go into that directory."
in .kshrc, i added:
alias cdl='cd $* | ls'
and it did the same thing...... it lists what's in the $* directory, but doesn't go into that directory. it's as if it's ignoring everything before ls, then just executing: ls directory_name
And you can also just type this at a command and then test it out.. sometimes before it takes affect when placing in your .kshrc file, you have to logout and back in so it rereads your file.
Originally posted by trickykid Patience, can't people sleep or work..
Double Quotes.. not Single Quotes.. notice mine:
alias cdl="cd $* | ls"
And then yours:
alias cdl='cd $* | ls'
And you can also just type this at a command and then test it out.. sometimes before it takes affect when placing in your .kshrc file, you have to logout and back in so it rereads your file.
Didn't work. Same problem. What's the difference between ' and " ???? All my aliases use ' and they all work fine, except for this one.
Also, why do I need to log out? Can't I just type: . .kshrc
Keyphrase is "In bash, I was able to get it to work using:
[size=large]but this doesn't seem to work in ksh[/size]. in ksh, i also tried:"
That indicates he tried both using the ksh shell to me...
But as for you problem, I'm not sure why its not working for you, as I tested it on my own machine using the korn shell and it works with no problems..
Did you try typing it at the shell prompt to test?
Code:
shell prompt> alias cdl="cd $* | ls"
shell prompt> alias
After typing the command to set the alias, just type alias at the command line and it will list all your current alias's, see if it shows up in that list for ya or not to verify.
Originally posted by acid_kewpie drew.... why the fsck are you piping a cd into ls???
alias cdl='cd $*; ls'
or maybe better:
alias cdl='cd $* && ls'
That didn't work either. I tried both ways shown above, and what it does is go back to my home directory (as if it's reading the cd by itself). I also tried it with quotes around $*, and all it does is the same thing it's always done: ls the contents of the named directory, but never go into that directory.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.