我在一些 Unix 书中经历了一个名为“pick”的命令,但不明白它到底是做什么的。下面是一个示例选择命令:
pick abc.*
Run Code Online (Sandbox Code Playgroud) I want to replaced all number with '@' symbol. I am using the below sed command , but not getting the desired result.
command -
echo "abc 434 pankaj 444" | sed 's/[0-9]*/@/g'
Run Code Online (Sandbox Code Playgroud)
Result -
@a@b@c@ @ @p@a@n@k@a@j@ @
Run Code Online (Sandbox Code Playgroud) 我有下面的shell脚本
var="this is a test"
ls -ltr| while read file
do
echo $var
done
echo $var
Run Code Online (Sandbox Code Playgroud)
我得到以下输出:
this is a test
this is a test
this is a test
Run Code Online (Sandbox Code Playgroud)
我如何在 while 循环中将变量“var”的值设置为“这是一个测试”,因为管道将产生一个新的子外壳,而且我也没有在主外壳中导出我的“var”变量?
据我所知,为了让孩子从父 shell 继承变量值,我们需要导出变量,但在这种情况下,变量值在没有“导出”语句的情况下被继承。
我有一个从其中一个网站获得的脚本。当我运行它时,它给出了“Hello”作为输出,但我无法理解脚本的工作原理。
谁能解释一下脚本实际上在做什么?
#!/bin/bash
echo hello
if test -t 1; then
# Stdout is a terminal.
exec >log
else
# Stdout is not a terminal.
npipe=/tmp/$$.tmp
trap "rm -f $npipe" EXIT
mknod $npipe p
tee <$npipe log &
exec 1>&-
exec 1>$npipe
fi
echo goodbye
Run Code Online (Sandbox Code Playgroud)