LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 06-05-2003, 12:27 PM   #16
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 235Reputation: 235Reputation: 235

The output of mine when I make the alias at a command:
Code:
> ~$ alias cdl='cd $* | ls'
> ~$ cdl /home
ftp/  joe/  smoovet/  test/
> ~$
 
Old 06-05-2003, 01:43 PM   #17
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
yeah but what directory are you then in? Actually i think i was wrong, and it's totally impossible. parameters can't be passed around in a simple alias, all it does is a basic text substitution and is not able to do that.

Last edited by acid_kewpie; 06-05-2003 at 01:46 PM.
 
Old 06-05-2003, 01:49 PM   #18
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 235Reputation: 235Reputation: 235
Quote:
Originally posted by acid_kewpie
yeah but what directory are you then in? Actually i think i was wrong, and it's totally impossible. parameters can't be passed around in a simple alias, all it does is a basic text substitution and is not able to do that.
If you notice the command prompt in my quote when I do this, I'm in /home/test or /home/~ and I run the command cdl /home
It works the same if I cdl / it will display the contents of /
 
Old 06-05-2003, 04:33 PM   #19
brian0918
Member
 
Registered: Apr 2003
Posts: 87

Original Poster
Rep: Reputation: 15
Yes, but are you then transfered INTO that directory? do a pwd after you execute the cdl command.
 
Old 06-05-2003, 04:34 PM   #20
brian0918
Member
 
Registered: Apr 2003
Posts: 87

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by acid_kewpie
yeah but what directory are you then in? Actually i think i was wrong, and it's totally impossible. parameters can't be passed around in a simple alias, all it does is a basic text substitution and is not able to do that.
Well, then how can it be done with a function? I got it to work in bash, but dont know the syntax for functions in ksh.
 
Old 06-05-2003, 04:54 PM   #21
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 235Reputation: 235Reputation: 235
You were right, didn't notice it wasn't cd'ing into the directory afterwards. Its sloppy looking and I'm sure there is a better way as I suck at scripting, especially korn shell as I rarely use it, you can do this which will work:

alias cdl='cd $*; ls; cd $*'
 
Old 06-06-2003, 06:32 PM   #22
zapp
LQ Newbie
 
Registered: May 2003
Distribution: slackware
Posts: 21

Rep: Reputation: 15
Rather than trying to address the symptom, lets look at the problem and try and solve it in a general fassion...


the problem is that by using an alias or a function, you create a new scope. ksh treats functions and aliases as mini-scripts, and when you run a script it creates a whole new sub-environment for that script to run in... when the script exits, you are left with the same environment you were in when you started it.

Because of this, any variables you set or cd's you make will be lost when you exit the function. Of course, filesystem changes remain because you're actually modifying permanent storage.

I've hit this problem several times before... not quite sure how to fix it Anyone?

Oh, and also... I believe the difference between ' and " is that ' is strict and " is not... meaning variables inside " " are processed by the shell, and variables inside ' ' are not.
for example:
a=this
b='$a'
c="$a"

echo $b <-- shows: $a
echo $c <--- shows: this
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting php5 socket functions to php3 socket functions mrobertson Programming 0 06-23-2005 10:11 AM
The ksh command Gins Linux - General 10 11-20-2004 07:56 PM
Doesnt source .kshrc when ksh is started pkan Linux - Newbie 2 03-08-2004 08:54 PM
function in .kshrc to cd then ls brian0918 Linux - Newbie 1 06-04-2003 03:42 PM
pointers to functions/member functions champ Programming 2 03-28-2003 07:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration