The reading assignment for next week is chapter 8 of Sobell, The Bourne Again Shell.
I have posted homework 7 here.
$(COMMAND)
jobs
is run with the -p option ...$ jobs -p 15521 15523 15525
$ jobs [1] Running ./bother.sh > /dev/null & [2]- Running ./bother.sh > /dev/null & [3]+ Running ./bother.sh > /dev/null & $ jobs -p 15579 15582 15585 $ kill $(jobs -p) $ jobs [1] Terminated ./bother.sh > /dev/null [2]- Terminated ./bother.sh > /dev/null [3]+ Terminated ./bother.sh > /dev/null $ jobs $
ps
you will see all running processes ...$ jobs [1]+ Running ./bother.sh > /dev/null & $ ps PID TTY TIME CMD 18389 pts/2 00:00:00 bash 19223 pts/2 00:00:00 bother.sh 19229 pts/2 00:00:00 sleep 19230 pts/2 00:00:00 ps
ps
will not show you any process ..$ ps -u USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND ghoffman 18389 0.0 0.1 23440 4768 pts/2 Ss 13:53 0:00 -bash ghoffman 19151 0.0 0.1 23312 4528 pts/3 Ss+ 14:55 0:00 -bash ghoffman 19223 0.0 0.0 12424 1412 pts/2 S 14:59 0:00 /bin/bash ./bother.sh ghoffman 19306 0.0 0.0 12424 1396 pts/3 S 15:02 0:00 /bin/bash ./bother.sh ghoffman 19309 0.0 0.0 7196 620 pts/3 S 15:02 0:00 sleep 5 ghoffman 19310 0.0 0.0 7196 620 pts/2 S 15:02 0:00 sleep 5 ghoffman 19311 0.0 0.0 18448 1324 pts/2 R+ 15:02 0:00 ps -u
ps -u
will show you these processesps -u
...kill
command
$ sleep 5 &
[1] 17895
$
$ sleep 5 & [1] 7431 $
[1]+ Done sleep 5
bg
commandbg
stands for backgroundbg
the job numberfg
(foreground) commandfg
kill
commandkill
you must tell it what to killkill
a process IDps
(process status) to get the process ID (PID)kill
...jobs
commandls
tty
$ ls -ld dir? drwxrwxrwx 2 it244gh libuuid 512 2011-09-30 15:26 dir1 drwxr--r-- 2 it244gh libuuid 512 2011-09-30 15:26 dir2 drwxrw---- 2 it244gh libuuid 512 2011-09-30 15:29 dir3 drwxrw---- 2 it244gh libuuid 512 2011-09-30 15:29 dir4
$ echo dir? dir1 dir2 dir3 dir4
$ ls -ld dir* drwxr-xr-x 2 it244gh libuuid 512 2011-10-04 13:52 dir drwxrwxrwx 2 it244gh libuuid 512 2011-09-30 15:26 dir1 drwxr-xr-x 2 it244gh libuuid 512 2011-10-04 13:53 dir10 drwxr--r-- 2 it244gh libuuid 512 2011-09-30 15:26 dir2 drwxrw---- 2 it244gh libuuid 512 2011-09-30 15:29 dir3 drwxr-xr-x 2 it244gh libuuid 512 2011-10-02 17:07 dir4
$ echo dir*
dir dir1 dir10 dir2 dir3 dir4
$ echo .*
. .. .addressbook .addressbook.lu .bash_history .cache .cshrc .login .msgsrc .pinerc .ssh
ls -ld dir[123] drwxrwxrwx 2 it244gh libuuid 512 2011-09-30 15:26 dir1 drwxr--r-- 2 it244gh libuuid 512 2011-09-30 15:26 dir2 drwxrw---- 2 it244gh libuuid 512 2011-09-30 15:29 dir3
$ echo dir[123]
dir1 dir2 dir3
ls -ld dir[1-3] drwxrwxrwx 2 it244gh libuuid 512 2011-09-30 15:26 dir1 drwxr--r-- 2 it244gh libuuid 512 2011-09-30 15:26 dir2 drwxrw---- 2 it244gh libuuid 512 2011-09-30 15:29 dir3
$ echo foo[!46] foo1 foo2 foo3 foo5 foo7 foo8 foo9
echo
is a built-inecho
on the disk
$ which echo /bin/echo
echo
...
$ /bin/echo foo
foo
which
on such a command will find nothing
$ which bg $
type
command will confirm this
$ type bg bg is a shell builtin
type
is also a built-in
$ type type type is a shell builtin
man
on a built-in command ...$ man bg No manual entry for bg
info
also has no information about built-inshelp
...help
with the name of a built-in ...$ help bg bg: bg [job_spec ...] Move jobs to the background. Place the jobs identified by each JOB_SPEC in the background, as if they had been started with `&". If JOB_SPEC is not present, the shell"s notion of the current job is used. Exit Status: Returns success unless job control is not enabled or an error occurs.
help
does not work for normal commands
$ help ls -bash: help: no help topics match `ls". Try `help help" or `man -k ls" or `info ls".
help
with no argument ...$ help GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu) These shell commands are defined internally. Type `help" to see this list. Type `help name" to find out more about the function `name". Use `info bash" to find out more about the shell in general. Use `man -k" or `info" to find out more about commands not in this list. A star (*) next to a name means that the command is disabled. job_spec [&] history [-c] [-d offset] [n] or history -anrw [filename> (( expression )) if COMMANDS; then COMMANDS; [ elif COMMANDS; then COMMA> . filename [arguments] jobs [-lnprs] [jobspec ...] or jobs -x command [args] : kill [-s sigspec | -n signum | -sigspec] pid | jobspec > [ arg... ] let arg [arg ...] [[ expression ]] local [option] name[=value] ... alias [-p] [name[=value] ... ] logout [n] bg [job_spec ...] mapfile [-n count] [-O origin] [-s count] [-t] [-u fd] > ...
sh
shell ...ksh
...csh
tcsh
bash
scriptsbash
...sh
bash
with the --posix
optionbash
run in a way more compatible with the POSIX standard$ echo $SHELL /bin/bash
cat
or ls
$ ps PID TTY TIME CMD 12778 pts/1 00:00:00 bash 12969 pts/1 00:00:00 ps $ bash $ ps PID TTY TIME CMD 12778 pts/1 00:00:00 bash 12970 pts/1 00:00:00 bash 12973 pts/1 00:00:00 ps $
bash
processesbash
shell is still running ...bash
...bash
shell ...script
to generate a typescript file ...sh
in a sub-shell
$ ps PID TTY TIME CMD 19874 pts/27 00:00:00 bash 20500 pts/27 00:00:00 ps $ sh $ ps PID TTY TIME CMD 19874 pts/27 00:00:00 bash 20510 pts/27 00:00:00 sh 20526 pts/27 00:00:00 ps
exit
$ ps PID TTY TIME CMD 19874 pts/27 00:00:00 bash 20737 pts/27 00:00:00 ps $ sh $ ps PID TTY TIME CMD 19874 pts/27 00:00:00 bash 20743 pts/27 00:00:00 sh 20751 pts/27 00:00:00 ps $ exit exit $ ps PID TTY TIME CMD 19874 pts/27 00:00:00 bash 20771 pts/27 00:00:00 ps