shell 基本语法-1
来源:互联网 发布:wep破解软件下载 编辑:程序博客网 时间:2024/05/29 16:50
[root@cdh2 test1]# NAME=ZONE[root@cdh2 test1]# [root@cdh2 test1]# echo $NAMEZONE[root@cdh2 test1]# eval echo $NAMEZONE[root@cdh2 test1]# lltotal 28-rw-r--r-- 1 root root 216 Jul 11 19:35 matchTest.scala-rw-r--r-- 1 root root 697 Jul 11 06:30 prt1.class-rw-r--r-- 1 root root 1066 Jul 11 06:30 prt1$.class-rw-r--r-- 1 root root 586 Jul 11 06:29 prt1.scala-rw-r--r-- 1 root root 594 Jul 11 06:26 prt.class-rw-r--r-- 1 root root 1052 Jul 11 06:26 prt$.class-rw-r--r-- 1 root root 120 Jul 11 06:19 prt.scala[root@cdh2 test1]# vi test.txt[root@cdh2 test1]# myfile="cat test.txt"[root@cdh2 test1]# [root@cdh2 test1]# echo $myfilecat test.txt[root@cdh2 test1]# eval echo $myfilecat test.txt[root@cdh2 test1]# myfile="cat test.txt"[root@cdh2 test1]# echo $myfilecat test.txt[root@cdh2 test1]# eval echo $myfilecat test.txt[root@cdh2 test1]# echo "Last argument is $(eval echo \$$#)"Last argument is /bin/bash[root@cdh2 test1]# [root@cdh2 test1]# echo "Last argument is $(eval echo $#)"Last argument is 0[root@cdh2 test1]# [root@cdh2 test1]# cd `dirname $0`[root@cdh2 bin]# cd -/user/local/test1[root@cdh2 test1]# pwd/user/local/test1[root@cdh2 test1]# echo `dirname $0`/bin[root@cdh2 test1]# DAY=`date +%Y%m%d`[root@cdh2 test1]# echo $DAY20160711[root@cdh2 test1]# DEL_DAY=`date -d -10days +%Y%m%d`[root@cdh2 test1]# echo $DEL_DAY20160701[root@cdh2 test1]# DEL_DAY=`date -d -12days +%Y%m%d`[root@cdh2 test1]# echo $DEL_DAY20160629 scala echo -e "ab\bc" echo -e "abc" echo -e "ab\bc" echo -e "a\tb\tc\nd\te\tf" echo "a\tb\tc\nd\te\tf" echo -e "\x61\t\x62\t\x63\n\x64\t\x65\t\x66" echo -e \ "\x61\t\x62\t\x63\n\x64\t\x65\t\x66" echo -e "\x61\t\x62\t\x63\n\x64\t\x65\t\x66" echo -e \ "\x61\t\x62\t\x63\n\x64\t\x65\t\x66" echo -e "\x61\t\x62\t\x63\n\x64\t\x65\t\x66" echo -e "\e[1;31m abcd \e[0m" echo -e "Mr. Shen Chao is the most honest man in LampBrother" pwd ll mkdir shell-test ll cd shell-test ll vim hello.sh cat hello.sh ll chmod 755 hello.sh ll hello.sh ./ hello.sh ./hello.sh bash hello.sh hello.sh sh hello.sh history[root@cdh1 shell-test]# history[root@cdh1 shell-test]# history 77 history[root@cdh1 shell-test]# history 77 history[root@cdh1 shell-test]# lltotal 4-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh[root@cdh1 shell-test]# history 77 history 78 ll 79 history[root@cdh1 shell-test]# history -c[root@cdh1 shell-test]# history 77 history[root@cdh1 shell-test]# history 77 history[root@cdh1 shell-test]# ls hello.sh[root@cdh1 shell-test]# ls -ltotal 4-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh[root@cdh1 shell-test]# lltotal 4-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh[root@cdh1 shell-test]# ls -ltrtotal 4-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh[root@cdh1 shell-test]# history 77 history 78 ls 79 ls -l 80 ll 81 ls -ltr 82 history[root@cdh1 shell-test]# !81ls -ltrtotal 4-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh[root@cdh1 shell-test]# !82history 77 history 78 ls 79 ls -l 80 ll 81 ls -ltr 82 history 83 ls -ltr 84 history[root@cdh1 shell-test]# !!history 77 history 78 ls 79 ls -l 80 ll 81 ls -ltr 82 history 83 ls -ltr 84 history[root@cdh1 shell-test]# !!history 77 history 78 ls 79 ls -l 80 ll 81 ls -ltr 82 history 83 ls -ltr 84 history[root@cdh1 shell-test]# history 77 history 78 ls 79 ls -l 80 ll 81 ls -ltr 82 history 83 ls -ltr 84 history[root@cdh1 shell-test]# [root@cdh1 shell-test]# echo -e "ab\bc"ac[root@cdh1 shell-test]# echo -e "abc"abc[root@cdh1 shell-test]# echo -e "ab\bc"ac[root@cdh1 shell-test]# echo -e "a\tb\tc\nd\te\tf"abcdef[root@cdh1 shell-test]# echo "a\tb\tc\nd\te\tf"a\tb\tc\nd\te\tf[root@cdh1 shell-test]# echo -e "\x61\t\x62\t\x63\n\x64\t\x65\t\x66"abcdef[root@cdh1 shell-test]# [root@cdh1 shell-test]# echo -e \> "\x61\t\x62\t\x63\n\x64\t\x65\t\x66"abcdef[root@cdh1 shell-test]# echo -e "\x61\t\x62\t\x63\n\x64\t\x65\t\x66"abcdef[root@cdh1 shell-test]# echo -e "\e[1;31m abcd \e[0m" abcd [root@cdh1 shell-test]# lltotal 4-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh[root@cdh1 shell-test]# cat hello.sh#vi hello.sh#!/bin/Bash#The first program# Author: shenchao (E-mail: shenchao@lampbrother.net)echo -e "Mr. Shen Chao is the most honest man in LampBrother"[root@cdh1 shell-test]# ./hello.shMr. Shen Chao is the most honest man in LampBrother[root@cdh1 shell-test]# sh hello.shMr. Shen Chao is the most honest man in LampBrother[root@cdh1 shell-test]# hello.shbash: hello.sh: command not found[root@cdh1 shell-test]# [root@cdh1 shell-test]# bash hello.shMr. Shen Chao is the most honest man in LampBrother[root@cdh1 shell-test]# chmod a-x hello.sh [root@cdh1 shell-test]# lltotal 4-rw-r--r-- 1 root root 164 Jul 13 23:25 hello.sh[root@cdh1 shell-test]# chmod a+x hello.sh [root@cdh1 shell-test]# lltotal 4-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh[root@cdh1 shell-test]# chmod a-x hello.sh [root@cdh1 shell-test]# lltotal 4-rw-r--r-- 1 root root 164 Jul 13 23:25 hello.sh[root@cdh1 shell-test]# chmod 755 hello.sh [root@cdh1 shell-test]# lltotal 4-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh[root@cdh1 shell-test]# [root@cdh1 shell-test]# cat hello.sh#vi hello.sh#!/bin/Bash#The first program# Author: shenchao (E-mail: shenchao@lampbrother.net)echo -e "Mr. Shen Chao is the most honest man in LampBrother"[root@cdh1 shell-test]# wc -c hello.sh 164 hello.sh[root@cdh1 shell-test]# wc -w hello.sh 23 hello.sh[root@cdh1 shell-test]# wc -l hello.sh 5 hello.sh[root@cdh1 shell-test]# ls ; date ; pwdhello.shWed Jul 13 23:55:32 PDT 2016/usr/local/shell-test[root@cdh1 shell-test]# ls /root/test || echo "no> > ;> "ls: cannot access /root/test: No such file or directoryno;[root@cdh1 shell-test]# ls /root/test || echo "no"ls: cannot access /root/test: No such file or directoryno[root@cdh1 shell-test]# ls /root/test && echo "yes"ls: cannot access /root/test: No such file or directory[root@cdh1 shell-test]# ls /root/test && echo "yes"ls: cannot access /root/test: No such file or directory[root@cdh1 shell-test]# ls test && echo "yes"ls: cannot access test: No such file or directory[root@cdh1 shell-test]# ls test ll echo "no"ls: cannot access test: No such file or directoryls: cannot access ll: No such file or directoryls: cannot access echo: No such file or directoryls: cannot access no: No such file or directory[root@cdh1 shell-test]# ls test || echo "no"ls: cannot access test: No such file or directoryno[root@cdh1 shell-test]# ls test && echo "yes"ls: cannot access test: No such file or directory[root@cdh1 shell-test]# [root@cdh1 shell-test]# lltotal 4-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh[root@cdh1 shell-test]# s test && echo "yes" || echo "no"bash: s: command not foundno[root@cdh1 shell-test]# ls test && echo "yes" || echo "no"ls: cannot access test: No such file or directoryno[root@cdh1 shell-test]# ls test && echo "yes" || echo "no"ls: cannot access test: No such file or directoryno[root@cdh1 shell-test]# lltotal 4-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh[root@cdh1 shell-test]# mkdir test[root@cdh1 shell-test]# lltotal 8-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.shdrwxr-xr-x 2 root root 4096 Jul 14 00:00 test[root@cdh1 shell-test]# ls test && echo "yes" || echo "no"yes[root@cdh1 shell-test]# ls test[root@cdh1 shell-test]# ls -l testtotal 0[root@cdh1 shell-test]# ls test && echo "yes" || echo "no"yes[root@cdh1 shell-test]# touch test/file-test.txt[root@cdh1 shell-test]# ls -l testtotal 0-rw-r--r-- 1 root root 0 Jul 14 00:01 file-test.txt[root@cdh1 shell-test]# ls test && echo "yes" || echo "no"file-test.txtyes[root@cdh1 shell-test]# netstat -an | grep "ESTABLISHED> ^C[root@cdh1 shell-test]# netstat -an | grep "ESTABLISHED"tcp 0 0 127.0.0.1:9000 127.0.0.1:51137 ESTABLISHED tcp 0 0 127.0.0.1:51137 127.0.0.1:9000 ESTABLISHED tcp 0 0 ::ffff:127.0.0.1:8031 ::ffff:127.0.0.1:37041 ESTABLISHED tcp 0 0 ::ffff:127.0.0.1:37041 ::ffff:127.0.0.1:8031 ESTABLISHED [root@cdh1 shell-test]# netstat -anunix 3 [ ] STREAM CONNECTED 9937 @/var/run/hald/dbus-EGc9boEf4Punix 3 [ ] STREAM CONNECTED 9936 unix 3 [ ] STREAM CONNECTED 9917 /var/run/dbus/system_bus_socketunix 3 [ ] STREAM CONNECTED 9916 unix 2 [ ] DGRAM 9878 unix 3 [ ] STREAM CONNECTED 9821 /var/run/dbus/system_bus_socketunix 3 [ ] STREAM CONNECTED 9820 unix 2 [ ] DGRAM 9819 unix 3 [ ] STREAM CONNECTED 9768 /var/run/dbus/system_bus_socketunix 3 [ ] STREAM CONNECTED 9767 unix 3 [ ] STREAM CONNECTED 9758 /var/run/dbus/system_bus_socketunix 3 [ ] STREAM CONNECTED 9757 unix 2 [ ] DGRAM 9751 unix 3 [ ] STREAM CONNECTED 9727 /var/run/dbus/system_bus_socketunix 3 [ ] STREAM CONNECTED 9726 unix 3 [ ] STREAM CONNECTED 9722 unix 3 [ ] STREAM CONNECTED 9721 unix 3 [ ] DGRAM 7176 unix 3 [ ] DGRAM 7175 ............ [root@cdh1 shell-test]# netstat -an | grep "ESTABLISHED"tcp 0 0 127.0.0.1:9000 127.0.0.1:51362 ESTABLISHED tcp 0 0 127.0.0.1:51362 127.0.0.1:9000 ESTABLISHED tcp 0 0 127.0.0.1:9000 127.0.0.1:51137 ESTABLISHED tcp 0 0 127.0.0.1:51137 127.0.0.1:9000 ESTABLISHED tcp 0 0 ::ffff:127.0.0.1:8031 ::ffff:127.0.0.1:37041 ESTABLISHED tcp 0 0 ::ffff:127.0.0.1:37041 ::ffff:127.0.0.1:8031 ESTABLISHED [root@cdh1 shell-test]# [root@cdh1 shell-test]# cat hello.sh #vi hello.sh#!/bin/Bash#The first program# Author: shenchao (E-mail: shenchao@lampbrother.net)echo -e "Mr. Shen Chao is the most honest man in LampBrother"[root@cdh1 shell-test]# cp hello.sh h.tx [root@cdh1 shell-test]# lltotal 12-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh-rwxr-xr-x 1 root root 164 Jul 14 00:08 h.txdrwxr-xr-x 2 root root 4096 Jul 14 00:01 test[root@cdh1 shell-test]# sh h.tx Mr. Shen Chao is the most honest man in LampBrother[root@cdh1 shell-test]# vim h.tx [root@cdh1 shell-test]# grep -n "world" h.tx 1:world[root@cdh1 shell-test]# grep -n "echo" h.tx 5:echo -e "Mr. Shen Chao is the most honest man in LampBrother"[root@cdh1 shell-test]# grep -n --color "echo" h.tx 5:echo -e "Mr. Shen Chao is the most honest man in LampBrother"[root@cdh1 shell-test]# cat h.tx world#!/bin/Bash#The first program# Author: shenchao (E-mail: shenchao@lampbrother.net)echo -e "Mr. Shen Chao is the most honest man in LampBrother"[root@cdh1 shell-test]# lltotal 12-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh-rwxr-xr-x 1 root root 157 Jul 14 00:28 h.txdrwxr-xr-x 2 root root 4096 Jul 14 00:01 test[root@cdh1 shell-test]# touch abc[root@cdh1 shell-test]# lltotal 12-rw-r--r-- 1 root root 0 Jul 14 00:45 abc-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh-rwxr-xr-x 1 root root 157 Jul 14 00:28 h.txdrwxr-xr-x 2 root root 4096 Jul 14 00:01 test[root@cdh1 shell-test]# lltotal 12-rw-r--r-- 1 root root 0 Jul 14 00:45 abc-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh-rwxr-xr-x 1 root root 157 Jul 14 00:28 h.txdrwxr-xr-x 2 root root 4096 Jul 14 00:01 test[root@cdh1 shell-test]# touch 012[root@cdh1 shell-test]# lltotal 12-rw-r--r-- 1 root root 0 Jul 14 00:52 012-rw-r--r-- 1 root root 0 Jul 14 00:45 abc-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh-rwxr-xr-x 1 root root 157 Jul 14 00:28 h.txdrwxr-xr-x 2 root root 4096 Jul 14 00:01 test[root@cdh1 shell-test]# ls ?abcls: cannot access ?abc: No such file or directory[root@cdh1 shell-test]# ls ?bcabc[root@cdh1 shell-test]# ls ?abcls: cannot access ?abc: No such file or directory[root@cdh1 shell-test]# ls *abcabc[root@cdh1 shell-test]# ls [0-9]*012[root@cdh1 shell-test]# lltotal 12-rw-r--r-- 1 root root 0 Jul 14 00:52 012-rw-r--r-- 1 root root 0 Jul 14 00:45 abc-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh-rwxr-xr-x 1 root root 157 Jul 14 00:28 h.txdrwxr-xr-x 2 root root 4096 Jul 14 00:01 test[root@cdh1 shell-test]# ls [^0-9]*abc hello.sh h.txtest:file-test.txt[root@cdh1 shell-test]# echo $(date)Thu Jul 14 00:54:09 PDT 2016[root@cdh1 shell-test]# dateThu Jul 14 00:54:13 PDT 2016[root@cdh1 shell-test]# echo `ls`012 abc hello.sh h.tx test[root@cdh1 shell-test]# echo lsls[root@cdh1 shell-test]# echo lsls[root@cdh1 shell-test]# echo 'ls'ls[root@cdh1 shell-test]# echo "ls"ls[root@cdh1 shell-test]# echo 'ls'ls[root@cdh1 shell-test]# echo `ls`012 abc hello.sh h.tx test[root@cdh1 shell-test]# dateThu Jul 14 00:57:15 PDT 2016[root@cdh1 shell-test]# echo `date`Thu Jul 14 00:57:22 PDT 2016[root@cdh1 shell-test]# echo `date`Thu Jul 14 01:27:44 PDT 2016[root@cdh1 shell-test]# name=sc[root@cdh1 shell-test]# echo $namesc[root@cdh1 shell-test]# echo `$name`bash: sc: command not found[root@cdh1 shell-test]# echo "$name"sc[root@cdh1 shell-test]# echo '$name'$name[root@cdh1 shell-test]# echo $date[root@cdh1 shell-test]# echo $(date)Thu Jul 14 01:29:36 PDT 2016[root@cdh1 shell-test]# echo "$(date)"Thu Jul 14 01:29:42 PDT 2016[root@cdh1 shell-test]# echo '$(date)'$(date)[root@cdh1 shell-test]# echo `$(date)`bash: Thu: command not found[root@cdh1 shell-test]# echo ‘$(date)'> > > > ^C[root@cdh1 shell-test]# [root@cdh1 shell-test]# name="shen chao"[root@cdh1 shell-test]# namebash: name: command not found[root@cdh1 shell-test]# namebash: name: command not found[root@cdh1 shell-test]# $namebash: shen: command not found[root@cdh1 shell-test]# echo $nameshen chao[root@cdh1 shell-test]# aa=123[root@cdh1 shell-test]# echo $aa123[root@cdh1 shell-test]# aa="$aa"456[root@cdh1 shell-test]# echo $aa123456[root@cdh1 shell-test]# aa=${aa}789[root@cdh1 shell-test]# echo $aa123456789[root@cdh1 shell-test]# aa=$aa456[root@cdh1 shell-test]# echo $aa[root@cdh1 shell-test]# aa="$aa"456[root@cdh1 shell-test]# echo $aa456[root@cdh1 shell-test]# echo $aa456[root@cdh1 shell-test]# aa=${aa}789[root@cdh1 shell-test]# echo $aa456789[root@cdh1 shell-test]# aa="$aa"456[root@cdh1 shell-test]# echo $aa456789456[root@cdh1 shell-test]# set aa[root@cdh1 shell-test]# setBASH=/bin/bashBASHOPTS=checkwinsize:cmdhist:expand_aliases:extquote:force_fignore:hostcomplete:interactive_comments:progcomp:promptvars:sourcepathBASH_ALIASES=()BASH_ARGC=()BASH_ARGV=()BASH_CMDS=()BASH_LINENO=()BASH_SOURCE=()BASH_VERSINFO=([0]="4" [1]="1" [2]="2" [3]="1" [4]="release" [5]="i386-redhat-linux-gnu")BASH_VERSION='4.1.2(1)-release'CLASSPATH=.:/user/local/jdk/lib:/user/local/jdk/jre/libCOLORS=/etc/DIR_COLORSCOLORTERM=gnome-terminalCOLUMNS=157DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-0fUn3bcLqe,guid=bcfba732c788ead6dd1ebda000000229DESKTOP_SESSION=gnomeDIRSTACK=()DISPLAY=:0.0EUID=0GDMSESSION=gnomeGDM_KEYBOARD_LAYOUT=usGDM_LANG=en_US.UTF-8GNOME_DESKTOP_SESSION_ID=this-is-deprecatedGNOME_KEYRING_PID=2383GNOME_KEYRING_SOCKET=/tmp/keyring-Tmor2J/socketGROUPS=()GTK_RC_FILES=/etc/gtk/gtkrc:/root/.gtkrc-1.2-gnome2G_BROKEN_FILENAMES=1HADOOP_HOME=/user/local/hadoop-2.6.0HADOOP_HOME_WARN_SUPPRESS=1HBASE_HOME=/user/local/hbase-0.98.20-hadoop2HISTCONTROL=ignoredupsHISTFILE=/root/.bash_historyHISTFILESIZE=1000HISTSIZE=1000HIVE_HOME=/usr/local/hiveHOME=/rootHOSTNAME=cdh1HOSTTYPE=i386ID=0IFS=$' \t\n'JAVA_HOME=/user/local/jdkJRE_HOME=/user/local/jdk/jreKAFKA_HOME=/user/local/kafka_2.9.2-0.8.1.1LANG=en_US.UTF-8LESSOPEN='|/usr/bin/lesspipe.sh %s'LINES=39LOGNAME=rootMACHTYPE=i386-redhat-linux-gnuMAIL=/var/spool/mail/rootMAILCHECK=60MAVEN_HOME=/usr/local/apache-maven-3.3.9OLDPWD=/usr/localOPTERR=1OPTIND=1ORBIT_SOCKETDIR=/tmp/orbit-root这样查看变量无效[root@cdh1 shell-test]# set aa;[root@cdh1 shell-test]# [root@cdh1 shell-test]# echo $aa456789456[root@cdh1 shell-test]# set aa[root@cdh1 shell-test]# set aa*[root@cdh1 shell-test]# echo $nameshen chao[root@cdh1 shell-test]# set >>vari.txt[root@cdh1 shell-test]# lltotal 20-rw-r--r-- 1 root root 0 Jul 14 00:52 012-rw-r--r-- 1 root root 0 Jul 14 00:45 abc-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh-rwxr-xr-x 1 root root 157 Jul 14 00:28 h.txdrwxr-xr-x 2 root root 4096 Jul 14 00:01 test-rw-r--r-- 1 root root 7296 Jul 14 02:14 vari.txt查看变量[root@cdh1 shell-test]# grep -n --color "name" vari.txt 88:name='shen chao'[root@cdh1 shell-test]# wc -l vari.txt 131 vari.txt[root@cdh1 shell-test]# [root@cdh1 shell-test]# grep -n --color "name" vari.txt 88:name='shen chao'[root@cdh1 shell-test]# set >>vari.txt[root@cdh1 shell-test]# set >>vari.txt[root@cdh1 shell-test]# echo $nameshen chao[root@cdh1 shell-test]# unset name[root@cdh1 shell-test]# echo $name[root@cdh1 shell-test]# set >>vari.txt应该找不到变量值的,但是 追加的所以还是能看到。[root@cdh1 shell-test]# grep -n --color "name" vari.txt 88:name='shen chao'219:name='shen chao'350:name='shen chao'覆盖[root@cdh1 shell-test]# set >vari.txt[root@cdh1 shell-test]# grep -n --color "name" vari.txt [root@cdh1 shell-test]# [root@cdh1 shell-test]# echo $nameshen chao[root@cdh1 shell-test]# \dbash: d: command not found[root@cdh1 shell-test]# su hadoop[hadoop@cdh1 shell-test]$ iduid=500(hadoop) gid=500(hadoop) groups=500(hadoop)[hadoop@cdh1 shell-test]$ echo $*[hadoop@cdh1 shell-test]$ echo $*00[hadoop@cdh1 shell-test]$ echo $0bash[hadoop@cdh1 shell-test]$ echo $1[hadoop@cdh1 shell-test]$ $#bash: 0: command not found[hadoop@cdh1 shell-test]$ lltotal 20-rw-r--r-- 1 root root 0 Jul 14 00:52 012-rw-r--r-- 1 root root 0 Jul 14 00:45 abc-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh-rwxr-xr-x 1 root root 157 Jul 14 00:28 h.txdrwxr-xr-x 2 root root 4096 Jul 14 00:01 test-rw-r--r-- 1 root root 7283 Jul 14 02:20 vari.txt[hadoop@cdh1 shell-test]$ vim test$.h[1]+ Stopped vim test$.h[hadoop@cdh1 shell-test]$ vim test.h[2]+ Stopped vim test.h[hadoop@cdh1 shell-test]$ lltotal 20-rw-r--r-- 1 root root 0 Jul 14 00:52 012-rw-r--r-- 1 root root 0 Jul 14 00:45 abc-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh-rwxr-xr-x 1 root root 157 Jul 14 00:28 h.txdrwxr-xr-x 2 root root 4096 Jul 14 00:01 test-rw-r--r-- 1 root root 7283 Jul 14 02:20 vari.txt[hadoop@cdh1 shell-test]$ vim test.sh[3]+ Stopped vim test.sh[hadoop@cdh1 shell-test]$ touch test.shtouch: cannot touch `test.sh': Permission denied[hadoop@cdh1 shell-test]$ su - rootPassword: ^Z[4]+ Stopped su - root[hadoop@cdh1 shell-test]$ exit;exitThere are stopped jobs.[hadoop@cdh1 shell-test]$ exitexitVim: Caught deadly signal TERMVim: preserving files...Vim: Caught deadly signal TERMVim: preserving files...Vim: Finished.Vim: Caught deadly signal TERMVim: preserving files...Vim: Finished.[root@cdh1 shell-test]# Vim: Finished.lltotal 20-rw-r--r-- 1 root root 0 Jul 14 00:52 012-rw-r--r-- 1 root root 0 Jul 14 00:45 abc-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh-rwxr-xr-x 1 root root 157 Jul 14 00:28 h.txdrwxr-xr-x 2 root root 4096 Jul 14 00:01 test-rw-r--r-- 1 root root 7283 Jul 14 02:20 vari.txt[root@cdh1 shell-test]# iduid=0(root) gid=0(root) groups=0(root)[root@cdh1 shell-test]# ]dbash: ]d: command not found[root@cdh1 shell-test]# \dbash: d: command not found[root@cdh1 shell-test]# vim test$.sh[root@cdh1 shell-test]# lbash: l: command not found[root@cdh1 shell-test]# lltotal 24-rw-r--r-- 1 root root 0 Jul 14 00:52 012-rw-r--r-- 1 root root 0 Jul 14 00:45 abc-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh-rwxr-xr-x 1 root root 157 Jul 14 00:28 h.txdrwxr-xr-x 2 root root 4096 Jul 14 00:01 test-rw-r--r-- 1 root root 93 Jul 14 02:37 test$.sh-rw-r--r-- 1 root root 7283 Jul 14 02:20 vari.txt[root@cdh1 shell-test]# chmod a+x test\$.sh [root@cdh1 shell-test]# lltotal 24-rw-r--r-- 1 root root 0 Jul 14 00:52 012-rw-r--r-- 1 root root 0 Jul 14 00:45 abc-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh-rwxr-xr-x 1 root root 157 Jul 14 00:28 h.txdrwxr-xr-x 2 root root 4096 Jul 14 00:01 test-rwxr-xr-x 1 root root 93 Jul 14 02:37 test$.sh-rw-r--r-- 1 root root 7283 Jul 14 02:20 vari.txt[root@cdh1 shell-test]# sh test\$.sh 12 34 46[root@cdh1 shell-test]# cat test\$.sh #!/bin/bashnum1=$1num2=$2sum=$(( $num1 + $num2))#变量sum的和是num1加num2echo $sum[root@cdh1 shell-test]# cp test\$.sh test1.sh[root@cdh1 shell-test]# cat test1.sh #!/bin/bashnum1=$1num2=$2sum=$(( $num1 + $num2))#变量sum的和是num1加num2echo $sum[root@cdh1 shell-test]# vim test1.sh [root@cdh1 shell-test]# lltotal 28-rw-r--r-- 1 root root 0 Jul 14 00:52 012-rw-r--r-- 1 root root 0 Jul 14 00:45 abc-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh-rwxr-xr-x 1 root root 157 Jul 14 00:28 h.txdrwxr-xr-x 2 root root 4096 Jul 14 00:01 test-rwxr-xr-x 1 root root 113 Jul 14 02:44 test1.sh-rwxr-xr-x 1 root root 93 Jul 14 02:37 test$.sh-rw-r--r-- 1 root root 7283 Jul 14 02:20 vari.txt[root@cdh1 shell-test]# sh test1.sh 23 34test1.sh: line 5: 23: command not found[root@cdh1 shell-test]# cat test1.sh #!/bin/bashnum1=$1num2=$2#sum=$(( $num1 + $num2))sum= $num1 + $num2#变量sum的和是num1加num2echo $sum[root@cdh1 shell-test]# vim test1.sh [root@cdh1 shell-test]# lltotal 28-rw-r--r-- 1 root root 0 Jul 14 00:52 012-rw-r--r-- 1 root root 0 Jul 14 00:45 abc-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh-rwxr-xr-x 1 root root 157 Jul 14 00:28 h.txdrwxr-xr-x 2 root root 4096 Jul 14 00:01 test-rwxr-xr-x 1 root root 116 Jul 14 02:46 test1.sh-rwxr-xr-x 1 root root 93 Jul 14 02:37 test$.sh-rw-r--r-- 1 root root 7283 Jul 14 02:20 vari.txt[root@cdh1 shell-test]# cat test1.sh #!/bin/bashnum1=$1num2=$2#sum=$(( $num1 + $num2))sum= $($num1 + $num2)#变量sum的和是num1加num2echo $sum[root@cdh1 shell-test]# sh test1.sh 23 34test1.sh: line 5: 23: command not found[root@cdh1 shell-test]# vim test1.sh [root@cdh1 shell-test]# cat test1.sh #!/bin/bashnum1=$1num2=$2#sum=$(( $num1 + $num2))sum= $(($num1)) + $(($num2))#变量sum的和是num1加num2echo $sum[root@cdh1 shell-test]# sh test1.sh 23 34test1.sh: line 5: 23: command not found[root@cdh1 shell-test]# vim test1.sh [root@cdh1 shell-test]# vim test1.sh [root@cdh1 shell-test]# sh test1.sh 23 34test1.sh: line 5: 57: command not found[root@cdh1 shell-test]# vim test1.sh [root@cdh1 shell-test]# sh test1.sh 23 34test1.sh: line 5: 57: command not found[root@cdh1 shell-test]# lltotal 28-rw-r--r-- 1 root root 0 Jul 14 00:52 012-rw-r--r-- 1 root root 0 Jul 14 00:45 abc-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh-rwxr-xr-x 1 root root 157 Jul 14 00:28 h.txdrwxr-xr-x 2 root root 4096 Jul 14 00:01 test-rwxr-xr-x 1 root root 119 Jul 14 02:51 test1.sh-rwxr-xr-x 1 root root 93 Jul 14 02:37 test$.sh-rw-r--r-- 1 root root 7283 Jul 14 02:20 vari.txt[root@cdh1 shell-test]# vim test1.sh [root@cdh1 shell-test]# sh test1.sh 23 3457[root@cdh1 shell-test]# cat test1.sh #!/bin/bashnum1=$1num2=$2#sum=$(( $num1 + $num2))sum=$(( $num1 + $num2))#变量sum的和是num1加num2echo $sum[root@cdh1 shell-test]# pwd/usr/local/shell-test[root@cdh1 shell-test]# df -lhFilesystem Size Used Avail Use% Mounted on/dev/sda2 5.7G 4.9G 545M 91% /tmpfs 504M 292K 503M 1% /dev/shm/dev/sda4 7.9G 4.4G 3.2G 59% /user/dev/sda1 291M 32M 245M 12% /boot[root@cdh1 shell-test]# lltotal 28-rw-r--r-- 1 root root 0 Jul 14 00:52 012-rw-r--r-- 1 root root 0 Jul 14 00:45 abc-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh-rwxr-xr-x 1 root root 157 Jul 14 00:28 h.txdrwxr-xr-x 2 root root 4096 Jul 14 00:01 test-rwxr-xr-x 1 root root 118 Jul 14 02:52 test1.sh-rwxr-xr-x 1 root root 93 Jul 14 02:37 test$.sh-rw-r--r-- 1 root root 7283 Jul 14 02:20 vari.txt[root@cdh1 shell-test]# vim echoTest.sh'[root@cdh1 shell-test]# lltotal 32-rw-r--r-- 1 root root 0 Jul 14 00:52 012-rw-r--r-- 1 root root 0 Jul 14 00:45 abc-rw-r--r-- 1 root root 149 Jul 14 03:15 echoTest.sh-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh-rwxr-xr-x 1 root root 157 Jul 14 00:28 h.txdrwxr-xr-x 2 root root 4096 Jul 14 00:01 test-rwxr-xr-x 1 root root 118 Jul 14 02:52 test1.sh-rwxr-xr-x 1 root root 93 Jul 14 02:37 test$.sh-rw-r--r-- 1 root root 7283 Jul 14 02:20 vari.txt[root@cdh1 shell-test]# chmod a+x echoTest.sh [root@cdh1 shell-test]# lltotal 32-rw-r--r-- 1 root root 0 Jul 14 00:52 012-rw-r--r-- 1 root root 0 Jul 14 00:45 abc-rwxr-xr-x 1 root root 149 Jul 14 03:15 echoTest.sh-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh-rwxr-xr-x 1 root root 157 Jul 14 00:28 h.txdrwxr-xr-x 2 root root 4096 Jul 14 00:01 test-rwxr-xr-x 1 root root 118 Jul 14 02:52 test1.sh-rwxr-xr-x 1 root root 93 Jul 14 02:37 test$.sh-rw-r--r-- 1 root root 7283 Jul 14 02:20 vari.txt[root@cdh1 shell-test]# sh echoTest.sh 1 3 4 6 78 90 234The parameters is: 1 3 4 6 78 90 234[root@cdh1 shell-test]# cat echoTest.sh#!/bin/bashfor i in "$*"#$*中的所有参数看成是一个整体,所以这个for循环只会循环一次doecho "The parameters is: $i"done[root@cdh1 shell-test]# cp echoTest.sh echoTest1.sh [root@cdh1 shell-test]# lltotal 36-rw-r--r-- 1 root root 0 Jul 14 00:52 012-rw-r--r-- 1 root root 0 Jul 14 00:45 abc-rwxr-xr-x 1 root root 149 Jul 14 03:23 echoTest1.sh-rwxr-xr-x 1 root root 149 Jul 14 03:15 echoTest.sh-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh-rwxr-xr-x 1 root root 157 Jul 14 00:28 h.txdrwxr-xr-x 2 root root 4096 Jul 14 00:01 test-rwxr-xr-x 1 root root 118 Jul 14 02:52 test1.sh-rwxr-xr-x 1 root root 93 Jul 14 02:37 test$.sh-rw-r--r-- 1 root root 7283 Jul 14 02:20 vari.txt[root@cdh1 shell-test]# vim echoTest1.sh [root@cdh1 shell-test]# sh echoTest1.sh 1 3 4 6 78 90 234The parameters is: 1The parameters is: 3The parameters is: 4The parameters is: 6The parameters is: 78The parameters is: 90The parameters is: 234[root@cdh1 shell-test]# cat echoTest1.sh #!/bin/bashfor i in "$@"#$*中的所有参数看成是一个整体,所以这个for循环只会循环一次doecho "The parameters is: $i"done[root@cdh1 shell-test]# [root@cdh1 shell-test]# $$bash: 4004: command not found[root@cdh1 shell-test]# echo $$4004[root@cdh1 shell-test]# echo $![root@cdh1 shell-test]# echo $$4004[root@cdh1 shell-test]# echo $?0[root@cdh1 shell-test]# $$bash: 4004: command not found[root@cdh1 shell-test]# echo $?127[root@cdh1 shell-test]# $?最后一次执行的命令的返回状态。如果这个变量的值为0,证明上一个命令正确执行;如果这个变量的值为非0(具体是哪个数,由命令自己来决定),则证明上一个命令执行不正确了。
0 0
- shell 基本语法-1
- Shell 基本语法
- Shell基本语法
- shell基本语法
- Shell 基本语法
- Shell的基本语法
- SHELL基本语法
- SHELL基本语法
- shell 基本语法总结
- Shell基本语法
- shell 基本语法
- Shell 基本语法
- shell基本语法
- shell基本语法二
- shell基本语法
- shell 脚本基本语法
- Shell 基本语法
- Shell 基本语法
- javascript跨域的4种方法和原理详解
- Linux网络编程入门-6
- Leetcode题解 24. Swap Nodes in Pairs
- 【例题】【线段树】连续区间
- STATE(状态)模式
- shell 基本语法-1
- HashMap、HashTable、ConcurrentHashMap、Queue
- HDU 5080 Colorful Toy (polya定理)
- 依赖注入
- 216. Combination Sum III
- 统计学习方法---条件随机场2
- android中EventBus总线框架的使用
- mysql存储过程总结
- Java排序算法——选择排序