fc to Edit and Run an Old CommandI have posted Homework 10 here.
As usual, it will be due next Sunday at 11:59 PM.
I have posted the answers to Quiz 7 here.
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 ...history 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
head or tail
$ !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 a built-in, so it executes quicklyfc will bring up an editor window ...fc with an event number ...fc ...fc will try to execute whatever you have left in the windowfc can also be used to view the history listfc will list the last 16 command linesfc to list all command lines starting with a certain numberfc -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 default
Command 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, it will list all aliases currently defined
$ 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, it will display the definition
$ alias ll
alias ll="ls -l'
$ echo 'My name is $name'
My name is $name
$ echo "My name is $name"
My name is Glenn Hoffman
FUNCTION_NAME ()
{
COMMANDS
}
$ echo3 () { echo $1; echo $1; echo $1;}
$ echo3 foo
foo
foo
foo
functionfunction is optional
$ print_args ()
> {
> echo "arg1: $1"
> echo "arg2: $2"
> }
$ print_args foo bar
arg1: foo
arg2: bar
noclobber optionset -o ...
$ set -o noclobber
$ echo "Go Red Sox" > output.txt
bash: output.txt: cannot overwrite existing file
set +o ...
$ set +o noclobber
$ cat output.txt
foo
$ echo "Go Red Sox" > output.txt
$ cat output.txt
Go Red Sox
$ 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/f12/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/it244gh
$ echo ~ghoffman
/home/ghoffman
$ 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 |
| / | Divison |
| % | 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
ls, Bash first runs the command
which bash
whichls 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 ...diff to look for differences ...