由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Linux版 - 命令后面加“> ./mylogfile.$$ 2>&1”这一串是什么意思呢?
相关主题
shell scripting 问题请教一个打印列的问题
靠,freenx client quiting以下的script能成立吗?应该怎么实现?
怎么把数据文件用动态图表的形式表示出来a sed question
如何从Bash script1 call Bash script2 ? 愿意发包子求指教!question about "stty"
每次打开IE总是出现hao123页面,也不是主页设置的页面请问怎么把两个行数相等的文件合并起来?
Windows XP下如何读取Ubuntu Linux里的文件?linux tcsh下less的问题
shell script question请教 GNU Screen display 的问题
how to auto execute a batch file on logging out or shutdownlinux如何生成可执行文件?
相关话题的讨论汇总
话题: positional话题: franky话题: expands话题: parameter话题: parameters
进入Linux版参与讨论
1 (共1页)
d*******o
发帖数: 5897
1
大致知道是输出重定向,但 $$ 2 >&1这些是什么意思呢?
S*A
发帖数: 7142
2
stderr redirect to stdout

【在 d*******o 的大作中提到】
: 大致知道是输出重定向,但 $$ 2 >&1这些是什么意思呢?
l*******G
发帖数: 1191
3
http://tille.garrels.be/training/bash/ch03s02.html#sect_03_02_0
$* Expands to the positional parameters, starting from one. When the
expansion occurs within double quotes, it expands to a single word with the
value of each parameter separated by the first character of the IFS special
variable.
$@ Expands to the positional parameters, starting from one. When the
expansion occurs within double quotes, each parameter expands to a separate
word.
$# Expands to the number of positional parameters in decimal.
$? Expands to the exit status of the most recently executed foreground
pipeline.
$- A hyphen expands to the current option flags as specified upon
invocation, by the set built-in command, or those set by the shell itself (
such as the -i).
$$ Expands to the process ID of the shell.
$! Expands to the process ID of the most recently executed background (
asynchronous) command.
$0 Expands to the name of the shell or shell script.
$_ The underscore variable is set at shell startup and contains the
absolute file name of the shell or script being executed as passed in the
argument list. Subsequently, it expands to the last argument to the previous
command, after expansion. It is also set to the full pathname of each
command executed and placed in the environment exported to that command.
When checking mail, this parameter holds the name of the mail file.
[Note] $* vs. $@
The implementation of “$*” has always been a problem and realistically
should have been replaced with the behavior of “$@”. In almost every case
where coders use “$*”, they mean “$@”. “$*” Can cause bugs and even
security holes in your software.
The positional parameters are the words following the name of a shell script
. They are put into the variables $1, $2, $3 and so on. As long as needed,
variables are added to an internal array. $# holds the total number of
parameters, as is demonstrated with this simple script:
#!/bin/bash
# positional.sh
# This script reads 3 positional parameters and prints them out.
POSPAR1="$1"
POSPAR2="$2"
POSPAR3="$3"
echo "$1 is the first positional parameter, \$1."
echo "$2 is the second positional parameter, \$2."
echo "$3 is the third positional parameter, \$3."
echo
echo "The total number of positional parameters is $#."
Upon execution one could give any numbers of arguments:
franky ~> positional.sh one two three four five
one is the first positional parameter, $1.
two is the second positional parameter, $2.
three is the third positional parameter, $3.
The total number of positional parameters is 5.
franky ~> positional.sh one two
one is the first positional parameter, $1.
two is the second positional parameter, $2.
is the third positional parameter, $3.
The total number of positional parameters is 2.
More on evaluating these parameters is in Chapter 7, Conditional statements
and the section called “The shift built-in”.
Some examples on the other special parameters:
franky ~> grep dictionary /usr/share/dict/words
dictionary
franky ~> echo $_
/usr/share/dict/words
franky ~> echo $$
10662
franky ~> mozilla &
[1] 11064
franky ~> echo $!
11064
franky ~> echo $0
bash
franky ~> echo $?
0
franky ~> ls doesnotexist
ls: doesnotexist: No such file or directory
franky ~> echo $?
1
franky ~>
User franky starts entering the grep command, which results in the
assignment of the _ variable. The process ID of his shell is 10662. After
putting a job in the background, the ! holds the process ID of the
backgrounded job. The shell running is bash. When a mistake is made, ? holds
an exit code different from 0 (zero).
d*******o
发帖数: 5897
4
很好,多谢了

the
special
separate

【在 l*******G 的大作中提到】
: http://tille.garrels.be/training/bash/ch03s02.html#sect_03_02_0
: $* Expands to the positional parameters, starting from one. When the
: expansion occurs within double quotes, it expands to a single word with the
: value of each parameter separated by the first character of the IFS special
: variable.
: $@ Expands to the positional parameters, starting from one. When the
: expansion occurs within double quotes, each parameter expands to a separate
: word.
: $# Expands to the number of positional parameters in decimal.
: $? Expands to the exit status of the most recently executed foreground

1 (共1页)
进入Linux版参与讨论
相关主题
linux如何生成可执行文件?每次打开IE总是出现hao123页面,也不是主页设置的页面
命令输出里的文件名空格在 make 里面怎么保留?Windows XP下如何读取Ubuntu Linux里的文件?
一个shell script 的问题shell script question
为什么bash file执行的结果与直接在命令行执行的结果不一样how to auto execute a batch file on logging out or shutdown
shell scripting 问题请教一个打印列的问题
靠,freenx client quiting以下的script能成立吗?应该怎么实现?
怎么把数据文件用动态图表的形式表示出来a sed question
如何从Bash script1 call Bash script2 ? 愿意发包子求指教!question about "stty"
相关话题的讨论汇总
话题: positional话题: franky话题: expands话题: parameter话题: parameters