Notes for Computer Information Technology 160
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sep19-more-commands.md 1.2KB

1 year ago
1 year ago
1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # September 19 - More Commands
  2. - Simple Commands
  3. - List of Commands
  4. - Compound Commands
  5. - Pipelining commands
  6. - I/O (Input Output) Redirection
  7. - Asynchronous Commands
  8. ## Simple Commands
  9. - name
  10. - location?
  11. - PATH=
  12. ## Where are Commands?
  13. ```
  14. $ ls # ls is a command
  15. $ /bin/ls # ls is a program in /bin
  16. $ ./ls # ls can be run from a relative path
  17. ```
  18. ## Command in Path
  19. ```
  20. $ echo $PATH
  21. /bin /sbin /usr/bin /usr/sbin [output varies per user]
  22. ```
  23. When a command is run, the system checks these locations for them.
  24. ## Executing a list of commands
  25. ```
  26. $ cmd1; cmd2 # do cmd1, then do cmd2
  27. $ echo $? # echo the status of cmd2 ($? is the status if the last command)
  28. $ cmd1 # do cmd1
  29. $ echo $? # echo the exit status of cmd1
  30. $ cmd1 && cmd2 # do cmd1, if cmd1 worked, do cmd2
  31. ```
  32. ## Compound Commands
  33. ```
  34. { ls; exit 0; }
  35. $ cd /tmp && { ls; exit 0; }
  36. $ cd /tmp && ( ls; exit 0 ) # run ls and exit in subshell
  37. ( ls; exit $? ) # exit subshell the same exit status of ls
  38. ```
  39. ## Math Commands
  40. ```
  41. $ $((5+3)) # do 5+3
  42. $ echo $? # exit status is 0
  43. $ $((3-3)) # do 3+3
  44. $ echo $? # exit status is 1 (because result is zero)
  45. ```
  46. ## "[[ ]]" Commands
  47. ```
  48. $ if [[ cd /tmp ]]; then
  49. ```