fc
to Edit and Run an Old CommandYou can connect to Gradescope to take weekly graded quiz today during the last 15 minutes of the class.
Once you start the quiz you have 15 minutes to finish it.
You can only take this quiz today.
There is not makeup for the weekly quiz because Gradescope does not permit it.
Homework 10 is posted here.
It is due this coming Sunday at 11:59 PM.
Are there any questions before I begin?
ssh ghoffman@pe15.cs.umb.edu
alias pe15='ssh ghoffman@pe15.cs.umb.edu'
pe15
ssh ghoffman@pe15.cs.umb.edu
alias pe15='ssh ghoffman@pe15.cs.umb.edu'in a file called from my ~/.bash_profile
pe15
history
command
$ history 2 exit 3 cd 4 cd it244/work 5 pwd 6 rm -rf * 7 cd ~/it244/work 8 pwd 9 cp ~ghoffman/examples_it244/bother.sh . 10 ls /home/ghoffman/examples_it244 11 cp ~ghoffman/examples_it244/bother.sh . 12 ./bother.sh 13 ./bother.sh & 14 jobs ...
history
without an argument it shows all eventshistory
followed by a number ...$ history 10 498 ps 499 exit 500 exit 501 history 502 cd 503 cd it244 504 cd work 505 ls 506 history 507 history 10
$ !517 echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
$ ! 517
517: command not found
$ !e
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
fc
to Edit and Run an Old Commandfc
(fix command) allows you
to edit a previous command line ...
fc
is useful when you want to run a previous command
line entry ...
fc
is a built-in, so it executes quicklyfc
will bring up an editor window ...fc
with an event number will put that command in the editor windowfc
can also be used to view the history listfc
will list the last 16 command linesfc
to list all command lines ...fc -l
followed by a space and a number
$ fc -l 522 522 echo $PATH 523 traceroute -a standford.edu 524 echo $PATH 525 echo $PATH 526 echo $PATH 527 fc -l
fc -l
to specify a range of eventsfc -l
with two numbers
$ fc -l 522 525 522 echo $PATH 523 traceroute -a standford.edu 524 echo $PATH 525 echo $PATH
emacs
modevim
modeemacs
mode by defaultCommand | Meaning |
---|---|
Control A | Move to the beginning of the line |
Control E | Move to the end of the line |
Control U | Remove everything from the text entry point to the beginning of the line |
Control K | Remove everything from the text entry point to the end of the line |
→ | Move the text entry point one character to the right |
← | Move the text entry point one character to the left |
↑ | Recall the previous command line entry in the history list |
↓ | Recall the following command line entry in the history list |
$ ls hw[Tab][Tab]
hw2/ hw4/ hw5/ hw6/
alias
commandalias
uses the following format in Bash
alias ALIAS_NAME=ALIAS_VALUE
alias la='ls -a'
alias
with no arguments ...$ alias alias bin='pu $bin' alias binl='ls $bin' alias ck755='ls -l *.sh | tr '\''-'\'' '\'' '\'' | grep '\''rwxr xr x'\''' ...
alias
with the name of an alias ...$ alias ll alias ll='ls -l'
$ ll agrs.sh total 4.0K -rwxr-xr-x 1 ghoffman faculty 70 Apr 8 14:12 agrs.sh
$ echo 'My name is $name' My name is $name
$ echo "My name is $name" My name is Glenn Hoffman
FUNCTION_NAME ()
{
COMMAND
COMMAND
...
}
$ echo3 () { echo $1; echo $1; echo $1;} $ echo3 foo foo foo foo
ls
or cat
bash operates when it runs
ls -l
bash --help
$ bash --help GNU bash, version 5.0.17(1)-release-(x86_64-pc-linux-gnu) Usage: bash [GNU long option] [option] ... bash [GNU long option] [option] script-file ... GNU long options: --debug --debugger --dump-po-strings --dump-strings --help --init-file --login --noediting --noprofile --norc --posix --pretty-print --rcfile --restricted --verbose --version Shell options: -ilrsD or -c command or -O shopt_option (invocation only) -abefhkmnptuvxBCHP or -o option Type `bash -c "help set"' for more information about shell options. Type `bash -c help' for more information about shell builtin commands. Use the `bashbug' command to report bugs. bash home page: <http://www.gnu.org/software/bash> General help using GNU software: <http://www.gnu.org/gethelp/>
set
...set
is a builtin ...set
can be found by running
help set
set
to enable an option in your current shellbash -x
$ cat find_scripts.sh #! /bin/bash cd $1 ls -1 | grep .py $ bash -x find_scripts.sh $s1fl + cd /home/ghoffman/course_files/it116_files + ls -1 + grep .py anon_awards.py average.py cheer_default.py ...
$ history 5 540 cat output.txt 541 echo "Go Red Sox" > output.txt 542 cat output.txt 543 echo foo 544 history 5 $ !543 echo foo foo
$ alias ll='ls -l' $ ll total 2 lrwxrwxrwx 1 it244gh man 34 Sep 6 21:09 it244 -> /courses/it244/s19/ghoffman/it244gh drwxr-xr-x 2 it244gh ugrad 512 Oct 27 09:16 work
$ touch foo{1,2,3,4,5}.txt $ ls foo1.txt foo2.txt foo3.txt foo4.txt foo5.txt
$ touch {a,ab,abc}.txt $ ls abc.txt ab.txt a.txt
$ touch {b , bc, b c d}.txt $ ls -l total 0 -rw-r--r-- 1 it244gh ugrad 0 Nov 14 10:37 , -rw-r--r-- 1 it244gh ugrad 0 Nov 14 10:37 b -rw-r--r-- 1 it244gh ugrad 0 Nov 14 10:37 {b -rw-r--r-- 1 it244gh ugrad 0 Nov 14 10:37 bc, -rw-r--r-- 1 it244gh ugrad 0 Nov 14 10:37 c -rw-r--r-- 1 it244gh ugrad 0 Nov 14 10:37 d}.txt
$ echo ~
/home/ghoffman
$ echo ~it244gh
/home/it244gh
$ echo ~xxx ~xxx
$ pwd
/home/it244gh/work
$ echo ~+
/home/it244gh/work
$ pwd
/home/it244gh/work
$ cd
$ pwd
/home/it244gh
$ echo ~-
/home/it244gh/work
$ echo $SHELL /bin/bash $ echo $? 0
$ echo 5 + 4 5 + 4
$ echo $(( 5 + 4 )) 9
$ a=5 $ b=3 $ echo $a $b 5 3 $ echo $(( $a - $b )) 2
Operator | Description |
---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
% | Remainder |
** | Exponentiation |
== | Equality |
!= | Inequality |
> | Greater than |
>= | Greater than or equal |
< | Less than |
<= | Less than or equal |
|| | Logical OR |
&& | Logical AND |
! | Logical N0T |
= | Assignment |
++ | Increment |
-- | Decrement |
$ echo $a $b 5 3 $ echo $(( a * b )) 15
$(COMMANDS)
$ today=$(date)
$ echo $today
Tue Oct 25 17:00:07 EDT 2011
$ ls -l `which bash` -rwxr-xr-x 1 root root 954896 2011-03-31 17:20 /bin/bash
which bashin a subshell
which
ls
can now take /bin/bash as its argument$ echo "Today is $(date +'%A, %B %d, %Y')" Today is Wednesday, November 13, 2013
$ args.sh foo bar bletch 3 args: [foo] [bar] [bletch]
args.sh 'foo bar bletch' 1 args: [foo bar bletch] $ args.sh "foo bar bletch" 1 args: [foo bar bletch]
$ args.sh $(date) 6 args: [Wed] [Apr] [12] [16:19:17] [EDT] [2017]
$ cheer="Let's go Red Sox!" $ args.sh $cheer 4 args: [Let's] [go] [Red] [Sox!]
$ args.sh $PATH 1 args: [/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/oracle/12.1/client64/bin:/home/ghoffman/bin/shell:/home/ghoffman/bin/python/umb:/home/ghoffman/bin:/home/ghoffman/bin/shell:/home/ghoffman/bin/python/umb] $ IFS=: $ args.sh $PATH 15 args: [/usr/local/sbin] [/usr/local/bin] [/usr/sbin] [/usr/bin] [/sbin] [/bin] [/usr/games] [/usr/local/games] [/snap/bin] [/usr/lib/oracle/12.1/client64/bin] [/home/ghoffman/bin/shell] [/home/ghoffman/bin/python/umb] [/home/ghoffman/bin] [/home/ghoffman/bin/shell] [/home/ghoffman/bin/python/umb]
$ ls t* test1.txt test2.txt test3.txt $ echo t* test1.txt test2.txt test3.txt
<(COMMAND)
$ diff -y <(ls -1 tia777/ce) <(ls -1 jgreen/ce) ce1 ce1 ce10 ce10 ce11 < ce2 ce2 ce3 ce3 ce4 ce4 ce5 ce5 ce6 ce6 ce7 ce7 ce8 ce8 ce9 ce9
ls
commands each running in their own subshell diff
to look for differences in these two "files"