1 Using The Shell VII Summary:
- Command Aliases
- Shell Functions
- Where To Go From Here
-
Shell FAQ
- How do I turn that &*#1.1 beep off?
- Why do I get ~~bash: command: command not found~~?
- The execution bit is set, I have permissions to execute but permission is denied anyway. Why?
- How do I change the file listing colors?
- I've put a script 'foo' into my '~/bin' directory, but every time I try to run it, a different command also called 'foo' is started. Why?
- What does ~~bash: command: bad interpreter~~ mean?
- My terminal freezes everytime I press ~~~~1.1
rsync -e ssh -z -t -r -vv ––progress /home/tom/web/muo/rsmuo/docs muo:/www/mandrakeuser/docs
alias upmuo='rsync -e ssh -z -t -r -vv ––progress /home/tom/web/muo/rsmuo/docs muo:/www/mandrakeuser/docs'
alias shortcut='command'
export MUOHOME=$HOME/web/muo/rsmuo/docs
alias upmuo="rsync -e ssh -z -t -r -vv ––progress $MUOHOME muo:/www/mandrakeuser/docs"
alias rm='ls -l'
Some aliases that might be useful (don't forget the quotes1.1 ): *
alias rpmq='rpm -qa | grep'
alias ls='ls -ho ––color | more'
alias use='du ––max-depth=1 | sort -n | more'
alias dkd='cd /usr/src/linux/Documentation'
Aliased directories may also be on removable media:
alias dlm='/mnt/cdrom/Mandrake/RPMS/'
Functions allow you to use arguments given to the function name at any place of the function command. With aliases, only one argument is allowed and that argument has to be at the end of the command line (like in the 'rpmq' alias above).
'$1' is a so-called 'positional parameter', it's a placeholder for the first argument given to the function. Of course there are more. ~~function apros() { apropos $1 | egrep -v "($2"; }~~ If you now run the 'apros' command like this: ~~apros name man_section_number~~ it searches for name, but excludes all man pages from man_section_number: ~~apros menu 3~~ returns all man page titles which contain 'menu', except those from section 3 (programming). Notice that you have to quote twice and that you have to use double quotes: * You must quote the 'egrep' search pattern in order to protect it from the shell. * You must use double quotes to get the second positional parameter interpreted correctly. * You must quote the round bracket again in order to tell 'egrep' to take it literally and not as a special control character . Tricky, ain't it? ;-). Shell functions are handled just like aliases: put them into your '.bashrc' to have them around permanently. [section index | BasicsIndex] 1.1 Where To Go From Here This article is but the beginning. Shell scripting can help you to automate a lot of tasks, to fix errors in scripts by others yourself and to accustom your Mandrake Linux system to your liking in (almost) every aspect. If you plan to learn one of the more complex programming languages out there, shell scripting is a good place to start because the basic concepts are similar. The [ BASH Programming - Introduction HOW-TO | http://www.ibiblio.org/mdw/HOWTO/Bash-Prog-Intro-HOWTO.html] will explain the topics covered in this article in more depth and introduce you to the world of shell programming. You can then continue with the very recommendable (and free) [ Advanced Bash-Scripting Guide | http://www.ibiblio.org/mdw/LDP/abs/html/index.html] by Mendel Cooper. If you prefer books, I can recommend S. Veeraraghavan's 'Teach Yourself Shell Programming', Sams Publishing. In contrast, I found 'Learning the bash Shell' by Newham/Rosenblatt, O'Reilly, rather unhelpful and confusing, but maybe that's just me ;-). Apart from that: practice, practice, practice. Read shell scripts by others and try to understand what they do, how and why. Don't run your test scripts as 'root'. Have fun. [section index | BasicsIndex] 1.1 Shell FAQ 1.1.1 How do I turn that &*#1.1 beep off? With this command: ~~setterm -blength 0~~ 1.1.1 Why do I get ~~bash: command: command not found~~? If it isn't a typo, most likely the command you are trying to execute is located in a directory which is not part of your $PATH. Supply the full path to the command. If you are in the same directory as the command, do ~~./command~~. 1.1 Why do I get ~~bash: command: Permission denied~~? In order for a file to be executable, the execute [permission | BasicsBpermis] must be set for the user who wants to execute the file. Do a: ~~chmod 755 file~~ If that doesn't work, read the article on permissions. 1.1.1 The execution bit is set, I have permissions to execute but permission is denied anyway. Why? Check the '/etc/fstab' entry of the partition where that file is. Make sure it doesn't contain the option 'noexec'. If it contains the option 'user', the option 'exec' must be set, too. 1.1.1 How do I change the file listing colors? Copy '/etc/DIR_COLORS' to your home directory and rename it to '.dir_colors'. Everything you need you'll find in that file. 1.1.1 I've put a script 'foo' into my '~/bin' directory, but every time I try to run it, a different command also called 'foo' is started. Why? Have a look at your $PATH and you will see that your personal '~/bin' directory is the last or at least very close to the end of the $PATH. The shell will search the directories listed in $PATH one after the other. As soon as it finds the first matching command, it executes this command. If there is a command on your system with the same name as your script, it is likely that this command will be executed, not your script. So rename your script. 1.1.1 What does ~~bash: command: bad interpreter~~ mean? This usually happens with third party installation binaries or Java applications. These applications need a shell of their own, so instead of ~~command~~ you have to run ~~sh command~~ 1.1.1 My terminal freezes everytime I press ~~~~1.1 Don't do that then ;-). ~~~~ sends a scroll lock command to the terminal. To release this lock, just press ~~~~. [section index | BasicsIndex]
Using The Shell VII
Version 1.10 last modified by Flink on 28/08/2006 at 10:48
Version 1.10 last modified by Flink on 28/08/2006 at 10:48