bash
-
Upload
gaurav-saxena -
Category
Technology
-
view
2.115 -
download
3
description
Transcript of bash
![Page 1: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/1.jpg)
bash
g11/2010
Akron Linux User Group
![Page 2: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/2.jpg)
macroprocessor
program that expands text and symbols to create large expressions
![Page 3: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/3.jpg)
shell
macroprocessor to execute commands
![Page 4: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/4.jpg)
shell standard
IEEE POSIX and Open Group shell specification
http://www.opengroup.org/onlinepubs/9699919799/nframe.html
All of these mean the same thing:
POSIX.1-2008IEEE Std 1003.1-2008 Open Group Technical Standard Base Specifications Issue 7"
![Page 5: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/5.jpg)
bash
shell that interprets certain default commands and that provides programmatic tools to write custom commands that don't exist can be used interactively (user types commands) or non-interactively (commands saved in a file)
respects POSIX.1-2008 standard maintained by Chet Ramey at the moment
![Page 6: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/6.jpg)
bash documentation
man bashman builtinsman rbashman bashbug
![Page 7: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/7.jpg)
bash feature summary 1/2source:http://tiswww.case.edu/php/chet/bash/bash-intro.html
editing and completion history and command re-entry job controlfunctions and aliasesarraysarithmeticansi c quote expansiontilde expansionbrace expansionsubstring capabilities
![Page 8: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/8.jpg)
bash feature summary 2/2source:http://tiswww.case.edu/php/chet/bash/bash-intro.html
indirect variable expansion i/o capabilitycontrol of built-in commandsshell optional behaviorprompt customizationsecuritydirectory stackposix modeinternationalizationcommand timing
![Page 9: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/9.jpg)
bash breakdown of tasks
read text (terminal, file, string)find words and operatorsparse tokens into commandsexpand certain tokens into lists
filenamescommandsarguments
handle redirectionsexecute commands wait for completion, or not
![Page 10: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/10.jpg)
bash: types of expansions
tilde~
variablestr=abcdefgh; echo ${str:-3:2}
commandecho `date`
processcmp < (echo "my life") <(echo "your life")
arithmeticstr=abcdefgh; echo ${str:((-3)):2}
braceecho sp{el,il,al}l
![Page 11: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/11.jpg)
bash modes
default (non POSIX)POSIX
![Page 12: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/12.jpg)
bash: POSIX mode
set -o posix #now in POSIX mode
![Page 13: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/13.jpg)
bash: POSIX mode
example of variance:set builtin does not show you func defs
![Page 14: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/14.jpg)
bash: POSIX mode
subset of bash core no process substitutionwhy use it?
![Page 15: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/15.jpg)
readline
bash + readline = productivityreadline allows you to make edits to commandsmaintained by Chet as welltypically gets updated along with bash
![Page 16: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/16.jpg)
readline documentation
man bashthen type /READLINE <enter>
![Page 17: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/17.jpg)
readline: take home
C-b move back oneC-f move forward oneC-d delete character I'm onC-u undo last keystroke (infinitely) C-a go to begin of lineC-e go to end of lineM-f jump forward (word)M-b jump backward (word)C-l clear screen, but keep my lineplenty more..
![Page 18: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/18.jpg)
bash tips
Execute your script, after marking it executable chmod +x myscript.sh; ./myscript.sh
![Page 19: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/19.jpg)
bash tips
Expansions!echo a{z,y,x}b
![Page 20: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/20.jpg)
bash tips
Appendecho "This is me" > saveforlaterecho "This is also me" >> saveforlater
![Page 21: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/21.jpg)
bash tips
Redirect output and error to different files. myprogram 1>myoutput 2>myerrors
To the same file. myprogram >&alloutput. myprogram &>alloutput
![Page 22: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/22.jpg)
bash tips
First or last few lineshead novel_that_i_started_but_didnt_finishtail novel_that_i_started_but_didnt_finishtail +1000 novel_that_i_started_but_didnt_finishtail +1000 --lines=2000 novel_that_i_started_but_didnt_finish
![Page 23: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/23.jpg)
bash tips
First or last few lineshead novel_that_i_started_but_didnt_finishtail novel_that_i_started_but_didnt_finishtail +1000 novel_that_i_started_but_didnt_finishtail +1000 --lines=2000 novel_that_i_started_but_didnt_finish
![Page 24: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/24.jpg)
bash tips
accidental overwritesecho "Test String" > 1.fileecho "Test String2" > 1.fileset -o noclobber echo "Test String3" > 1.fileecho "Test String3" >> 1.file cat 1.file
![Page 25: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/25.jpg)
bash tips
accidental overwritesecho "Test String" > 1.fileecho "Test String2" > 1.fileset -o noclobber echo "Test String3" > 1.file #no goecho "Test String3" >> 1.file #still works cat 1.file
![Page 26: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/26.jpg)
bash tips
incidental (conscious) overwritesecho "Test String" > 1.fileecho "Test String2" > 1.fileset -o noclobber echo "Test String3" >| 1.file #goesecho "Test String3" >> 1.file #still works cat 1.file
![Page 27: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/27.jpg)
bash tips
modern loops:for i in $(seq 1 10); do echo $i; done
![Page 28: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/28.jpg)
bash tips
loops from the past:for i in {1..10}; do echo $i; done
![Page 29: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/29.jpg)
bash tips
loops that are the most portable:for ((i=0; i<10; i++)); do echo $i; done
![Page 30: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/30.jpg)
bash tips
portable stdout:printf "%s" "short string"
![Page 31: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/31.jpg)
bash tips
what does the machine see:hexdump -C myfavoritebigfile
![Page 32: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/32.jpg)
YOUR bash tips
![Page 33: bash](https://reader034.fdocuments.in/reader034/viewer/2022052619/5554ab8cb4c905fd608b5201/html5/thumbnails/33.jpg)
bash online
wiki:http://en.wikipedia.org/wiki/Bash_%28Unix_shell%29stallman:http://www.gnu.org/software/bash/chet:http://tiswww.case.edu/php/chet/bash/bashtop.htmlaustin:http://www.unix.org/single_unix_specification_v3/