[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
howtos:cli_manual:shells [2012/10/06 23:37 (UTC)] – [Configuring a shell prompt] sycamorex | howtos:cli_manual:shells [2012/10/28 21:39 (UTC)] (current) – [~/.bashrc] sycamorex | ||
---|---|---|---|
Line 174: | Line 174: | ||
export MY_EXPORTED_VAR=" | export MY_EXPORTED_VAR=" | ||
- | By exporting a variable you make it accessible to any sub-shells created in the current shell. In other words, if you want a script to be aware of a variable, you need to export it. | + | By exporting a variable you make it accessible to any sub-shells created in the current shell. In other words, if you want a script to be aware of a variable, you need to export it. If you want to see all the exported variables in the current shell, type: |
+ | < | ||
Line 369: | Line 370: | ||
< | < | ||
- | Do not forget to source root's '' | + | Do not forget to source root's '' |
===Prompt Background Colour=== | ===Prompt Background Colour=== | ||
Line 383: | Line 384: | ||
< | < | ||
- | =====Building | + | =====Building |
+ | |||
+ | Aliases are shortcuts or abbreviated commands used in a shell in order to avoid typing long commands. Aliases are usually created to modify existing commands by adding some flags or to join a few commands in order to create new custom commands. | ||
+ | |||
+ | An example of an alias would be: | ||
+ | |||
+ | < | ||
+ | |||
+ | Now typing '' | ||
+ | |||
+ | Another example would be creating a shortcut to query installed packages on a Slackware system: | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | emacs-24.2-x86_64-1</ | ||
+ | |||
+ | The general syntax of an alias is: | ||
+ | |||
+ | < | ||
+ | |||
+ | To create a temporary alias for the current session, just define it directly on a command line. It will not be remembered when you start another session. To store an alias permanently to be accessible by the shell in the future, place it in '' | ||
+ | |||
+ | If you need to (temporarily) switch off an alias you can use the '' | ||
+ | |||
+ | < | ||
+ | emacs-24.2-x86_64-1 | ||
+ | user@darkstar: | ||
+ | user@darkstar: | ||
+ | bash: qp: command not found</ | ||
+ | |||
+ | If you run a (long) command on a regular basis, it might be convenient to create an alias for it. | ||
+ | |||
+ | Have a look at some more examples of aliases below. This may help you create your own aliases. | ||
+ | |||
+ | <note important> | ||
+ | |||
+ | < | ||
+ | alias ll | ||
+ | alias lla=' | ||
+ | alias mkdir=' | ||
+ | alias rm='rm -i' | ||
+ | alias 1.='cd .. ; pwd' | ||
+ | alias 2.='cd ../.. ; pwd' | ||
+ | alias 3.='cd ../../.. ; pwd' | ||
+ | alias 4.='cd ../../../.. ; pwd' | ||
+ | alias h=' | ||
+ | alias eq=' | ||
+ | |||
+ | alias emc=' | ||
+ | alias org=' | ||
+ | alias ci3=' | ||
+ | |||
+ | alias psp=' | ||
+ | alias wic=' | ||
+ | |||
+ | alias dl='cd / | ||
+ | alias mftp=' | ||
+ | alias mylaptop=' | ||
+ | alias myserver=' | ||
+ | |||
+ | alias t=' | ||
+ | alias r2j=' | ||
+ | </ | ||
+ | |||
+ | === Aliases and Security === | ||
+ | Sometimes aliases may pose a security risk in a sense that they can spoof other commands (eg. on compromised systems). Consider the following: | ||
+ | |||
+ | < | ||
+ | |||
+ | To view currently set aliases, just type '' | ||
+ | |||
+ | < | ||
+ | |||
+ | Escaping the command with \ prevents any alias expansion in case someone had tried to spoof the '' | ||
+ | |||
+ | < | ||
+ | /home/user | ||
+ | user@darkstar: | ||
+ | user@darkstar: | ||
+ | 666 | ||
+ | user@darkstar: | ||
+ | / | ||
=====Creating functions===== | =====Creating functions===== | ||
+ | |||
+ | FIXME | ||
+ | =====~/ | ||
+ | |||
+ | At the moment our '' | ||
+ | |||
+ | < | ||
+ | # load the system-wide environment | ||
+ | source / | ||
+ | |||
+ | # Add a directory with your scripts to the path. | ||
+ | PATH=$PATH: | ||
+ | |||
+ | # Configure the CDPATH variable to include a frequently visited directories | ||
+ | CDPATH=$CDPATH: | ||
+ | |||
+ | # Set the default editor | ||
+ | export VISUAL=vim | ||
+ | export EDITOR=vim | ||
+ | |||
+ | # Defining foreground variables for the prompt | ||
+ | P_BLACK=" | ||
+ | P_RED=" | ||
+ | P_GREEN=" | ||
+ | P_YELLOW=" | ||
+ | P_BLUE=" | ||
+ | P_MAGENTA=" | ||
+ | P_CYAN=" | ||
+ | P_WHITE=" | ||
+ | P_RESET=" | ||
+ | |||
+ | # Setting a fancy prompt for the current user | ||
+ | export PS1=" | ||
+ | |||
+ | # Setting aliases | ||
+ | alias e=' | ||
+ | alias ll='ls -l' | ||
+ | alias lla=' | ||
+ | alias mkdir=' | ||
+ | alias rm='rm -i' | ||
+ | alias 1.='cd .. ; pwd' | ||
+ | alias 2.='cd ../.. ; pwd' | ||
+ | alias 3.='cd ../../.. ; pwd' | ||
+ | alias 4.='cd ../../../.. ; pwd' | ||
+ | alias h=' | ||
+ | alias eq=' | ||
+ | |||
+ | alias emc=' | ||
+ | alias org=' | ||
+ | alias ci3=' | ||
+ | |||
+ | alias psp=' | ||
+ | alias wic=' | ||
+ | |||
+ | alias dl='cd / | ||
+ | alias mftp=' | ||
+ | alias mylaptop=' | ||
+ | alias myserver=' | ||
+ | |||
+ | alias t=' | ||
+ | alias r2j=' | ||
+ | |||
+ | ####################################################################### | ||
+ | # | ||
+ | ####################################################################### | ||
+ | |||
+ | # Specify an NNTP Server | ||
+ | export NNTPSERVER=' | ||
+ | |||
+ | # To take advantage of multicore CPUs you can use the MAKEFLAGS variable. | ||
+ | # For example the equivalent of "make -j2" would be: | ||
+ | # export MAKEFLAGS=" | ||
+ | # Uncomment the above line to use it. | ||
+ | |||
+ | </ | ||
+ | |||
=====Other configuration files===== | =====Other configuration files===== | ||