dirs
- Displays the Directory Stackpushd
- Pushes a Directory onto the Stackpopd
- Pops a Directory off the StackYou should have read chapter 8 of Sobell, The Bourne Again Shell.
I have posted Homework 8 here.
As usual, it will be due next Sunday at 11:59 PM.
source
command
source .bash_profile
( ) | Runs whatever commands are enclosed in the parentheses in a sub-shell |
---|---|
$( ) | Command substitution: runs the commands enclosed in the parentheses in a subshell and returns their value to the command line, replacing the dollar sign, the parentheses and everything in them with this value |
(( )) | Evaluates an arithmetic expression: by default, Unix treats everything as text, but this command evaluates whatever it encloses as a numerical, rather than a string, expression |
$(( )) | Arithmetic expansion: evaluates an arithmetic expression and returns its value at that place on the command line |
[ ] | The test command: used to evaluate a boolean expression in constructs like if clauses |
[[ ]] | The conditional expression: similar to [ ] but adds string comparisons |
Name File Descriptor Standard input 0 Standard output 1 Standard error 2
$ ./repeat.sh < test.txt
Enter several lines
Type X on a line by itself when done
You entered
-----------
123456789
abcdefg
987654321
hijklmnop
foo
bar
bletch
X
./repeat.sh < test.txt
Unix thinks of this as
./repeat.sh 0< test.txt
where 0 is the file descriptor for standard input
$ echo "Hello there" > hello.txt
Unix thinks of this as meaning
$ echo "Hello there" 1> hello.txt
$ ls xxxx ls: cannot access xxxx: No such file or directory $ ls xxxx 2> error.txt $ cat error.txt ls: cannot access xxxx: No such file or directory
tty
bash
bash
...#! /bin/bash
$ echo Here are the contents of my home directory ; ls -l ; echo Here are the contents of my home directory total 40 drwxr-xr-x 4 ghoffman grad 4096 Oct 15 2016 bin drwxr-xr-x 6 ghoffman faculty 4096 Oct 23 2016 code drwxr-xr-x 6 ghoffman faculty 4096 Sep 9 2016 course_files drwxr-xr-x 7 ghoffman grad 4096 May 25 10:53 html lrwxrwxrwx 1 root root 38 May 30 21:10 it116 -> /courses/it116/sum17/ghoffman/ghoffman lrwxrwxrwx 1 ghoffman faculty 52 Feb 20 09:43 it116_test -> /home/ghoffman/code/it116_code/testing_scripts_it116 lrwxrwxrwx 1 ghoffman faculty 38 May 30 16:59 it244 -> /courses/it244/sum17/ghoffman/ghoffman lrwxrwxrwx 1 ghoffman faculty 52 Feb 3 09:10 it244_test -> /home/ghoffman/code/it244_code/testing_scripts_it244 drwxr----- 2 ghoffman faculty 4096 Mar 27 09:43 mail drwxrwxr-x 10 ghoffman faculty 4096 Jul 6 08:51 public_html drwxrwxr-x 4 ghoffman faculty 4096 Jun 12 08:40 submitted drwxr----- 4 ghoffman faculty 4096 Jun 23 11:38 tests_taken drwxr--r-- 2 ghoffman faculty 4096 Jul 11 17:55 tmp drwxr----- 4 ghoffman faculty 4096 Sep 22 2016 xrchiv
./bother.sh &
$ ./bother.sh > /dev/null & ./bother.sh > /dev/null & ./bother.sh > /dev/null & jobs [1] 1794 [2] 1795 [3] 1796 [1] Running ./bother.sh > /dev/null & [2]- Running ./bother.sh > /dev/null & [3]+ Running ./bother.sh > /dev/null &
$ kill $(jobs -p) ; jobs
[1] Running ./bother.sh > /dev/null &
[2]- Running ./bother.sh > /dev/null &
[3]+ Running ./bother.sh > /dev/null &
[1] Terminated ./bother.sh > /dev/null
[2]- Terminated ./bother.sh > /dev/null
[3]+ Terminated ./bother.sh > /dev/null
$ echo asdfasdfasdfasdfasdfasdfasdf asdfasdfasdfasdfasdfasdfasdfasdfasd fasdfasdfasdfasdfasdfasdfasdfasdfas dfasdfasdfasfads Done asdfasdfasdfasdfasdfasdfasdfasdfasd fasdfasdfasdfasdfasdfasdfasdfasdfas dfasdfasdfasdfasdfasdfasdfasdfasdfa sdfasfads Done
$ echo asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfas dfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasd fasdfasdfasfads Done asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfa sdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfas dfasfads Done
$ echo A man \ > A plan \ > A canal \ > Panama A man A plan A canal Panama
( cd ~/bar ; tar-xvf - )
cd ~/foo ; tar -cf - . | ( cd ~/bar ; tar-xvf - )
tar
on the files you find theretar
, - means either standard input or standard output ...tar
would go to cd
...cd
would ignore it ...tar
is waiting for something from standard inputdirs
pushd
popd
cd
keeps no record of where you have beenpushd
and popd
use the directory stack to change your location ...dirs
- Displays the Directory Stackdirs
displays the current contents of the directory stackdirs
simply displays the current directory
$pwd ~/it244/hw5 $ dirs ~/it244/hw5
dirs
always uses a tilde, ~ ...pushd
- Pushes a Directory onto the Stackpushd
changes your current directory, just like cd
...pushd
$ pwd /home/it244gh/it244/hw5 $ dirs ~/it244/hw5 $ pushd ~ghoffman $ pwd /home/ghoffman $ dirs /home/ghoffman ~/it244/hw5
pushd
$ pushd examples_it244/ ~/examples_it244 ~ $ pushd ~it244gh /home/it244gh ~/examples_it244 ~ $ pushd it244/work/ /home/it244gh/it244/work /home/it244gh ~/examples_it244 ~ $ pushd /home/it244gh /home/it244gh/it244/work ~/examples_it244 ~ $ dirs /home/it244gh /home/it244gh/it244/work ~/examples_it244 ~
pushd
a plus sign followed by a numberpopd
- Pops a Directory off the Stackpopd
changes your current directory to another directory ...popd
$ pwd /home/it244gh/it244/hw5 $ dirs ~/it244/hw5 $ pushd ~ghoffman /home/ghoffman ~/it244/hw5 $ pwd /home/ghoffman $ popd ~/it244/hw5 $ pwd /home/it244gh/it244/hw5 $ dirs ~/it244/hw5
popd
a plus sign followed by a number
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
VARIABLE_NAME=VALUE
$ foo=bar
$ echo $foo
bar
$ hello="Hello there" $ echo $hello Hello there
$ foo=bar $ echo $foo bar $ cat print_foo.sh #!/bin/bash # # Prints the value of the variable foo echo foo = $foo $ ./print_foo.sh foo =
$ echo $foo
bar
$ foo=bletch ./print_foo.sh
foo = bletch
$ echo $foo
bar
export
$ echo $foo
bar
$ export foo=bletch
$ echo $foo
bletch
$ ./print_foo.sh
foo = bletch
env
command without an argument ...$ env TERM=xterm-color SHELL=/bin/bash SSH_CLIENT=66.92.76.9 53785 22 OLDPWD=/home/it244gh SSH_TTY=/dev/pts/8 USER=it244gh ...
Variable Value HOME The absolute pathname of your home directory PATH The list of directories the shell will search when looking for the executable file associated with a command you entered at the command line SHELL The absolute pathname of your default shell The absolute pathname of the file that holds your mail PS1 Your command line prompt - what you see after entering each command PS2 The secondary prompt - what you see if you continue a command to a second line
$ foo=bling $ echo $foo bling