ksh functions in .kshrc
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. Thanks for any help. |
Why didn't you try the same thing that's in .bashrc?
function cdl() { cd $1 ls } |
Quote:
What is $1 ? What are you exporting or defining as $1 ? Maybe that is the reason why its not doing nothing. Take a look at this example .kshrc file: http://publibn.boulder.ibm.com/doc_l...iles/kshrc.htm |
what i want is something similar to:
cd asdfadf which goes into the directory... but instead, cdl asdfadf will go into the directory, then display its contents. i thought i could use $1 to represent aasdfadf |
Instead of using the function, its much easier to just create an alias like this:
alias cdl="cd $* | ls" And that should work and function the same way. |
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 |
Well....?
|
Quote:
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. |
Quote:
function cdl { cd $1 ls } |
Quote:
Also, why do I need to log out? Can't I just type: . .kshrc |
Yes you can just type . .kshrc
|
Quote:
[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... :rolleyes: 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" |
drew.... why the fsck are you piping a cd into ls??? :D
alias cdl='cd $*; ls' or maybe better: alias cdl='cd $* && ls' |
My bad, it is single quote.. but as acid pointed out.. there are several ways to do it using alias..
|
Quote:
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. |
All times are GMT -5. The time now is 11:22 PM. |