[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.

Welcome to the Slackware Documentation Project

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
howtos:cli_manual:shells [2012/10/09 18:04 (UTC)] – [Building aliases] A new section added sycamorexhowtos:cli_manual:shells [2012/10/28 21:39 (UTC)] (current) – [~/.bashrc] sycamorex
Line 174: Line 174:
 export MY_EXPORTED_VAR="More text"</code> export MY_EXPORTED_VAR="More text"</code>
  
-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: 
 +<code>export -p</code>
  
  
Line 369: Line 370:
 <code>PS1="$P_GREEN\u$P_RED@$P_YELLOW\h:$P_CYAN\w$P_RED\\$ $P_RESET"</code> <code>PS1="$P_GREEN\u$P_RED@$P_YELLOW\h:$P_CYAN\w$P_RED\\$ $P_RESET"</code>
  
-Do not forget to source root's ''.bashrc'' in its ''.bash_profile'' to make sure it works for both ''su'' and ''su -''.+Do not forget to source root's ''.bashrc'' in its ''.bash_profile'' to make sure it works for both non-login (''su''and login (''su -'') shells.
  
 ===Prompt Background Colour=== ===Prompt Background Colour===
Line 415: Line 416:
 bash: qp: command not found</code> bash: qp: command not found</code>
  
-If you run a (long) command on a regular basis, it might be convenient to create an alias for it. To view all the currently set aliases, just type ''alias'' at the command prompt+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. Have a look at some more examples of aliases below. This may help you create your own aliases.
Line 449: Line 450:
 </code> </code>
  
 +=== 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:
  
 +<code>alias ls='some_nasty_command'</code>
 +
 +To view currently set aliases, just type ''alias'' at the command prompt. To clear all the aliases, type:
 +
 +<code>\unalias -a</code>
 +
 +Escaping the command with \ prevents any alias expansion in case someone had tried to spoof the ''unalias'' command. See the following:
 +
 +<code>user@darkstar:~$ pwd
 +/home/user
 +user@darkstar:~$ alias pwd='echo 666'
 +user@darkstar:~$ pwd
 +666
 +user@darkstar:~$ \pwd
 +/home/user</code>
 =====Creating functions===== =====Creating functions=====
 +
 +FIXME
 =====~/.bashrc===== =====~/.bashrc=====
 +
 +At the moment our ''~/.bashrc'' looks as follows. At the bottom you'll see some additional settings that have not been discussed. The comments above them should clarify their meaning.
 +
 +<code>
 +# load the system-wide environment
 +source /etc/profile
 +
 +# Add a directory with your scripts to the path.
 +PATH=$PATH:~/bin
 +
 +# Configure the CDPATH variable to include a frequently visited directories
 +CDPATH=$CDPATH:~/data/projects/slackbuilds/
 +
 +# Set the default editor
 +export VISUAL=vim
 +export EDITOR=vim
 +
 +# Defining foreground variables for the prompt
 +P_BLACK="\[$(tput setaf 0)\]"
 +P_RED="\[$(tput setaf 1)\]"
 +P_GREEN="\[$(tput setaf 2)\]"
 +P_YELLOW="\[$(tput setaf 3)\]"
 +P_BLUE="\[$(tput setaf 4)\]"
 +P_MAGENTA="\[$(tput setaf 5)\]"
 +P_CYAN="\[$(tput setaf 6)\]"
 +P_WHITE="\[$(tput setaf 7)\]"
 +P_RESET="\[$(tput sgr0)\]"
 +
 +# Setting a fancy prompt for the current user
 +export PS1="$P_GREEN\u$P_RED@$P_YELLOW\h:$P_CYAN\w$P_BLUE\\$ $P_RESET"
 +
 +# Setting aliases
 +alias e='exit'
 +alias ll='ls -l'
 +alias lla='ls -al | less'
 +alias mkdir='mkdir -pv' 
 +alias rm='rm -i' 
 +alias 1.='cd .. ; pwd'
 +alias 2.='cd ../.. ; pwd'
 +alias 3.='cd ../../.. ; pwd'
 +alias 4.='cd ../../../.. ; pwd'
 +alias h='history'
 +alias eq='alsamixer -D equal'
 +
 +alias emc='emacs -nw'
 +alias org='emacs -nw /home/user/data/todo.org'
 +alias ci3='vim /home/user/.i3/config'
 +
 +alias psp='ps aux | grep'
 +alias wic='nmap -sP 192.168.1.0/24'
 +
 +alias dl='cd /home/user/data/downloads/ ; ls'
 +alias mftp='lftp sftp://user@ftp.server.com'
 +alias mylaptop='ssh user@ip_address'
 +alias myserver='ssh user@ip_address'
 +
 +alias t='task'
 +alias r2j='mkdir jpg; ufraw-batch --out-type=jpeg --out-path=./jpg ./*.NEF'
 +
 +#######################################################################
 +#                       Additional settings:                          #
 +#######################################################################
 +
 +# Specify an NNTP Server 
 +export NNTPSERVER='aioe.org'
 +
 +# To take advantage of multicore CPUs you can use the MAKEFLAGS variable. 
 +# For example the equivalent of "make -j2" would be:
 +# export MAKEFLAGS="-j2"
 +# Uncomment the above line to use it.
 +
 +</code>
 +
 =====Other configuration files===== =====Other configuration files=====
  
 howtos:cli_manual:shells ()