|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
cd then ls -l
Hi,
I'm trying to create a little script: if [ -d $1 ] then cd $1 ls -l $1 fi so I can make a new command: cl that does both. simple enough but I noticed that after executing I'm returned to my original location. How do I surpress that behaviour? I'm using bash-2 on HP-UX 11. Thanks. |
| Sponsored Links | |
|
|
|
#2
|
||||
|
||||
|
That's because it's executed in a subshell. You could add a function to .bashrc something like Code:
cl()
{
if [ -d "$1" ]; then
cd "$1"
ls -l
fi
}Cheers ZB |
| Sponsored Links | ||
|
|
|
#3
|
||||
|
||||
|
Have a question here ....
See the following 2 aliases .... alias cl="cd scripts ; ls -lrt" alias cla="cd $1 ; ls -lrt" Here is the concern ... 1)After running the first alias command 'cl' , the current directory is $HOME/scripts 2) After running the second alias command 'cla scripts' , the current directory is $HOME only. For both alias commands , o/p is nothing but list of "scripts" directory. Any ideas what's happening here .... ? |
|
#4
|
||||
|
||||
|
Quote:
|
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
. ./yourscript.sh
|
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
the result, by the way
a bit late maybe but I thought I might post the result:
cl() { if [ -d $1 ] then cd $1 ls -la else cd $HOME ls -la fi } then ./cl.sh in my .profile works very well on ksh and in bash |
| Sponsored Links | ||
|
|