Command Line session 2

Conceptor's picture
Submitted by Conceptor on Wed, 18/08/2004 - 12:12pm.
::

After finishing open topics and question from last session . session 2 will be started.

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

    1. Command line completion
    2. 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
      1. Vi/Vim editor Introduction and running commands.
      2. Starting and handling background processes.
         $ jobs
         $ bg
         $ fg

        Using '&' to release console.

        1. Introduction to bash shell scripting .

      3. Scripting Basics
      4. Scripting Basics
      5. Create Shell scripts
      6. Making Script Executable
      7. Generating Output
      8. Handling Output
      9. Exit status
      10. Conditional Execution
        note : 
&& = Logical AND || = Logical OR $ grep conceptor /etc/passwd || echo 'there is no conceptor entry'

  • Conditional Execution Using if Statement
  • I hope to finish all these topics , as far as I hope that audience understand them and practice.

    1. !/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

    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

    pekwm& WMPID=$!
    ... #various desktop components
    ...
    wait $WMPID
    

    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 &quot;$PWD&quot;
       then
          DIRCOLOR=$C_owner
       elif -w &quot;$PWD&quot;
       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 &quot;$SSH_AUTH_SOCK&quot;
       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 PS1
    

    the 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"

    Alaa's picture

    Comment viewing options

    Select your preferred way to display the comments and click "Save settings" to activate your changes.