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 |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
12-20-2016, 01:35 PM
|
#1
|
Member
Registered: Aug 2012
Posts: 316
Rep: 
|
cd && ls
hi guys,
on a previous linux system i was able to write this little "alias/script"
Code:
alias ll='ls -alhF'
change_dir_and_list
{
cd "$1" && ll
}
alias cd='change_dir_and_list'
and it worked perfectly, now the little "alias/script" doesn't work. if i remember right before i was running redhat enterprise 7. now my linux box is running centOS linux 6.7
can somebody tell me what i missed or if there's another way to do this?
my goal is so that everytime i cd a listing of all the files in that directory is shown
thanks!
Todd
|
|
|
12-20-2016, 02:25 PM
|
#2
|
Member
Registered: Jan 2009
Location: Sydney, Australia
Distribution: Fedora,CentOS
Posts: 758
Rep: 
|
What exactly doesn't work? I had to change the first line as ll is already defined on my F25 system
Quote:
[tim@comedian ~]$ cat elias
alias lll='ls -alhF'
change_dir_and_list
{
cd "$1" && lll
}
alias cd='change_dir_and_list'
[tim@comedian ~]$ ./elias Downloads/
./elias: line 2: change_dir_and_list: command not found
./elias: line 4: lll: command not found
|
|
|
|
12-20-2016, 02:53 PM
|
#3
|
Member
Registered: Aug 2012
Posts: 316
Original Poster
Rep: 
|
it comes back saying
Code:
change_dir_and_list: command not found
Last edited by atjurhs; 12-20-2016 at 02:56 PM.
Reason: corrected cmd/error syntax
|
|
|
12-20-2016, 02:53 PM
|
#4
|
LQ Veteran
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Rep: 
|
If I may offer:
Code:
alias cd="cd $1 && ls -alhF"
|
|
|
12-20-2016, 03:03 PM
|
#5
|
Senior Member
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Fedora, OpenSUSE, FreeBSD, OpenBSD, macOS (hack). Past: Debian, Arch, RedHat (pre-RHEL).
Posts: 1,335
|
Quote:
Originally Posted by atjurhs
hi guys,
on a previous linux system i was able to write this little "alias/script"
Code:
alias ll='ls -alhF'
change_dir_and_list
{
cd "$1" && ll
}
alias cd='change_dir_and_list'
|
How are you using this "alias/script?"
If you are using it as a script, why are you even using an alias in it? That alias goes out of scope when the script completes.
If you want to use the alias or included function from the shell prompt, you must put in a startup file or at the least source it before trying to use it, or the shell will not no about it.
Before use, or add it somewhere to your shell's startup files:
or The period is a synonym for the source builtin. I prefer using the more verbose source as it's obvious (I hate going through my distro's stock startup files to find stuff, as searching for a period is a PITA).
Last edited by goumba; 12-20-2016 at 03:06 PM.
|
|
|
12-20-2016, 04:28 PM
|
#6
|
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,908
|
I believe the change_dir_and_list must have a "(){" immediately following the command, as in
Code:
change_dir_and_list(){
cd "$1" && ll
}
alias cd='change_dir_and_list'
|
|
|
12-21-2016, 08:41 AM
|
#7
|
Member
Registered: Aug 2012
Posts: 316
Original Poster
Rep: 
|
Quote:
Originally Posted by jpollard
I believe the change_dir_and_list must have a "(){" immediately following the command, as in
Code:
change_dir_and_list(){
cd "$1" && ll
}
alias cd='change_dir_and_list'
|
jpollard, you are correct the alias does required the () to run, i forgot to include that
many thanks!
Todd
|
|
|
12-21-2016, 09:21 AM
|
#8
|
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,037
|
Remember to mark as SOLVED once you have a solution
|
|
|
12-21-2016, 01:19 PM
|
#9
|
Member
Registered: Aug 2012
Posts: 316
Original Poster
Rep: 
|
yep, grail, it's been a while since my last posting, i forgot, thanks for the reminder!
|
|
|
All times are GMT -5. The time now is 05:30 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|