Notes for Computer Information Technology 160
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

sep19-more-commands.md 1.2KB

September 19 - More Commands

  • Simple Commands
  • List of Commands
  • Compound Commands
  • Pipelining commands
  • I/O (Input Output) Redirection
  • Asynchronous Commands

Simple Commands

  • name
  • location?
  • PATH=

Where are Commands?

$ ls      # ls is a command

$ /bin/ls # ls is a program in /bin

$ ./ls    # ls can be run from a relative path

Command in Path

$ echo $PATH

/bin /sbin /usr/bin /usr/sbin [output varies per user]

When a command is run, the system checks these locations for them.

Executing a list of commands

$ cmd1; cmd2 # do cmd1, then do cmd2

$ echo $?    # echo the status of cmd2 ($? is the status if the last command)

$ cmd1       # do cmd1

$ echo $?    # echo the exit status of cmd1

$ cmd1 && cmd2 # do cmd1, if cmd1 worked, do cmd2

Compound Commands

{ ls; exit 0; }

$ cd /tmp && { ls; exit 0; }

$ cd /tmp && ( ls; exit 0 ) # run ls and exit in subshell

( ls; exit $? ) # exit subshell the same exit status of ls

Math Commands

$ $((5+3)) # do 5+3

$ echo $?  # exit status is 0

$ $((3-3)) # do 3+3

$ echo $?  # exit status is 1 (because result is zero)

” Commands

$ if [[ cd /tmp ]]; then