小编Pan*_*dey的帖子

unix 'pick' 命令有什么作用?

我在一些 Unix 书中经历了一个名为“pick”的命令,但不明白它到底是做什么的。下面是一个示例选择命令:

pick abc.*
Run Code Online (Sandbox Code Playgroud)

shell-script

22
推荐指数
1
解决办法
2594
查看次数

Using sed to replace numbers with @ inserts @ between every character

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)

sed

4
推荐指数
1
解决办法
3186
查看次数

在子shell中继承的变量而不在主shell中导出

我有下面的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 继承变量值,我们需要导出变量,但在这种情况下,变量值在没有“导出”语句的情况下被继承。

shell pipe subshell

3
推荐指数
1
解决办法
1333
查看次数

请解释 exec、trap、mknod、tee 的作用

我有一个从其中一个网站获得的脚本。当我运行它时,它给出了“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)

bash io-redirection shell-script

-7
推荐指数
1
解决办法
353
查看次数

标签 统计

shell-script ×2

bash ×1

io-redirection ×1

pipe ×1

sed ×1

shell ×1

subshell ×1