Command Line session 2
Submitted by Conceptor on Wed, 18/08/2004 - 12:12pm.
::
After finishing open topics and question from last session . session 2 will be started.
- Redirection and Pipes
$ ls -l > /dev/pts/? ur current pts.
$ ls -l > / output
$ wc -l < output
$ ls -l / | wc -l > count
$ ls -l / | wc -l |tee /dev/tty9 > count_file
When you get the result of this command ,you were notified that u shouldn't list ur username on every entry .
$ ls -l /opt/new_apps > apps_list
the comman way is using sed stream editor.
$ sed 's/root/ /' apps_list
once again some of your friends tells u that he want the file to appear like a funky format and he told u that the file is not changing ,what will u do ? there was an idea to run this
$ sed 's/root/root and dude /' apps_list
try to save the output.
- Command line completion
- File Operating and filtering-determine file contents-.
$ cat file_name
$ less file_name
$ more file_name
$ head file_name
$ tail file_name
using grep , cut ,paste , sort , diff , uniq wc ,aspell.
$ sort -t : -k 3 -k 3 -n /etc/passwd
$ wc -lcw filename
$ cut -d: -f7 | sort| uniq
$ paste -d: file_ids file_dates > merged_file
- Vi/Vim editor Introduction and running commands.
- Starting and handling background processes.
$ jobs
$ bg
$ fg
Using '&' to release console.
- Introduction to bash shell scripting .
- Scripting Basics
- Scripting Basics
- Create Shell scripts
- Making Script Executable
- Generating Output
- Handling Output
- Exit status
- Conditional Execution
note :
I hope to finish all these topics , as far as I hope that audience understand them and practice.
- !/bin/bash read TIME session_end='8:30' if $TIME -lt $session_end then echo 'mount options , introduction to network commands' else echo 'See you later' fi
- Conceptor's blog
- Login or register to post comments
- 1528 reads


I think we need extra session
I think we need extra session for bash scripting, the time was not enough , while it was very benifitable
important variables
$? holds the exit code or return code of the previous command
$! holds the pid of the most recent backgrounded command.
for instance in my .xinitrc file I have
this way the window manager starts before anything else and I still get to make it the session manager (ie the session ends when pekwm terminates, due to the wait clause).
another interesting example of scripting is making inteligent bash prompts here is mine which is ripped from somewhere
export T_normal='1;34' export T_bold=1 export T_underline=4 export C_owner='0;32' export C_write='0;36' export C_nowrite='0;31' export C_error='0;31' export DIRCOLOR=$T_normal export EXIT_CODE=0 export CODE_COLOR='4;31' export CODE_STRING= export USER_STYLE=$T_normal prompt_command() { EXIT_CODE=$? DIRCOLOR=$T_normal # Color-code directory if -O "$PWD" then DIRCOLOR=$C_owner elif -w "$PWD" then DIRCOLOR=$C_write else DIRCOLOR=$C_nowrite fi # Add a bold red number for exitcode if its nonzero if $EXIT_CODE -ne 0 then #CODE_COLOR=$C_error CODE_STRING=\($EXIT_CODE\) else #CODE_COLOR=$T_normal CODE_STRING= fi # Underline username if ssh-agent is running if -S "$SSH_AUTH_SOCK" then USER_STYLE=$T_underline else USER_STYLE=$T_normal fi } export PROMPT_COMMAND=prompt_command if ${TERM:0:5} = xterm then PS1='\\e0;\u@\h:\w\007\]' else PS1='' fi if ${TERM:0:5} = dumb then PS1='\u::\w$CODE_STRING$ ' else PS1=$PS1'\\e[${USER_STYLE}m\\u\\e[0;35m::\[\e[${DIRCOLOR}m\\w\\e[${CODE_COLOR}m\$CODE_STRING\\e[0;35m\$\\e[0;m\ ' fi export PS1the funky bits are color codes ignore them.
cheers,
Alaa
http://www.manalaa.net
"u know i once dream that the office of mobinil is from el 7`os :S and the one that answer u and tell u rasidak a girl called ghada"