在屏幕上显示 bash 脚本中特定命令的结果
Display results of specific commands in bash script to screen
在我的脚本中,我正在执行一些 git 命令,但我希望命令的输出在脚本运行时显示在屏幕上。
OS X Yosemite,如果重要的话。
#!/bin/sh
# get the Git command from parameter
if [ $# -eq 0 ];
then
echo "no arguments supplied"
exit 1
fi
cmd=
echo "doing some stuff"
# do some stuff (not echoed to screen)
echo "executing command"
# this is the command I want to echo output to screen
git $cmd
echo "doing some other"
# do other stuff (not echoed to screen)
您不想显示在屏幕上的内容可以重定向到 /dev/null
,如下所示:
ls /tmp > /dev/null
除非您特别说明,否则您的 git
命令的结果将回显到屏幕上。
在脚本开头添加 set -x
将在执行前打印命令。
示例:
#!/bin/sh
set -x
# get the Git command from parameter
if [ $# -eq 0 ];
then
echo "no arguments supplied"
exit 1
fi
# ...
在我的脚本中,我正在执行一些 git 命令,但我希望命令的输出在脚本运行时显示在屏幕上。
OS X Yosemite,如果重要的话。
#!/bin/sh
# get the Git command from parameter
if [ $# -eq 0 ];
then
echo "no arguments supplied"
exit 1
fi
cmd=
echo "doing some stuff"
# do some stuff (not echoed to screen)
echo "executing command"
# this is the command I want to echo output to screen
git $cmd
echo "doing some other"
# do other stuff (not echoed to screen)
您不想显示在屏幕上的内容可以重定向到 /dev/null
,如下所示:
ls /tmp > /dev/null
除非您特别说明,否则您的 git
命令的结果将回显到屏幕上。
在脚本开头添加 set -x
将在执行前打印命令。
示例:
#!/bin/sh
set -x
# get the Git command from parameter
if [ $# -eq 0 ];
then
echo "no arguments supplied"
exit 1
fi
# ...