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!
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I am stuck here, I don't know why this alias doesn't work:
alias cs='cd $1; ls'
When I type cs new_dir, I want to list contents of the new_dir and STAY IN IT. But it always takes me back to the original directory after listing. How can I fix this and, more importantly, WHY doesn't it work?
Thanks for your help.
The "pecking order" is roughly:[list=1][*]alias[*]function[*]script[/list=1]
Aliases are fast, easy, & hidden; but can't use arguments / parameters.
Functions are fast, easy, & can take arguments / parameters; but aren't hidden -- they clutter the environment.
Scripts can take arguments, do not clutter the environment -- they can be long; but they are:
Not as fast as aliases or functions.
Must have extra lines -- e.g. '#! /bin/bash'.
Must be in separate files.
Must be placed in a directory in the PATH.
In my experience, Debian & MEPIS boxen are notorious for environmental function clutter.
If you want to check your box, run the following 3-part command:
The lines in the output are:[list=1][*]Just the environment variables.[*]All the shell variables stripped of the functions, at least as they are written on my MEPIS 3.3 box.[*]All the shell variables, including the functions.[/list=1] Mine looks like this:
Unfortunately, your example doesn't give the results he's after, slackie. It lists the current directory and then changes to the correct one.
aliases definitely do not take parameters, as stated in the man page. Your example and frankie_DJ's example work "by accident". $1 is expanded to nothing when the alias runs, so your alias expands to: cs thisdir => ls; cd thisdir
(hopefully the bold helps illustrate why your alias appears to work, from a current-directory viewpoint)
frankie's example works the same way. cx file => chmod u+x file
if you change frankie's alias command to this:
alias cx="chmod u+x $1;"
it will no longer work, because the filename parameter you give it will appear after the semicolon.