Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell 在bashrc中运行函数或别名集,或通过nohup运行概要文件_Shell_Nohup_.bash Profile_Bash - Fatal编程技术网

Shell 在bashrc中运行函数或别名集,或通过nohup运行概要文件

Shell 在bashrc中运行函数或别名集,或通过nohup运行概要文件,shell,nohup,.bash-profile,bash,Shell,Nohup,.bash Profile,Bash,我的问题与此类似。 我花了很多时间来定制包含在.bashrc中的函数 我希望它与nohup一起运行,因为我希望以这种方式多次运行命令 for i in `cat mylist`; do nohup myfunction $i 'mycommand' & done 有什么建议吗 nohup不能与函数一起工作。您需要创建一个shell脚本来包装和执行函数。然后可以使用nohup运行shell脚本 像这样: test.sh chmod+x test.sh,然后在for循环中调用它: for

我的问题与此类似。

我花了很多时间来定制包含在.bashrc中的函数 我希望它与nohup一起运行,因为我希望以这种方式多次运行命令

for i in `cat mylist`; do nohup myfunction $i 'mycommand' & done

有什么建议吗

nohup
不能与函数一起工作。您需要创建一个shell脚本来包装和执行函数。然后可以使用
nohup运行shell脚本

像这样:

test.sh

chmod+x test.sh
,然后在
for
循环中调用它:

for i in `cat mylist`; do 
    nohup ./test.sh $i 'mycommand' & 
done

nohup
不能与函数一起工作。您需要创建一个shell脚本来包装和执行函数。然后可以使用
nohup运行shell脚本

像这样:

test.sh

chmod+x test.sh
,然后在
for
循环中调用它:

for i in `cat mylist`; do 
    nohup ./test.sh $i 'mycommand' & 
done

通过
nohup
调用
bash-c
(本质上与运行外部bash脚本相同),可以对函数(而不是别名)执行此操作

为了使其正常工作,您需要将函数标记为导出的

# define the function
echo_args() {
  printf '<%s> ' "$@"
  printf "\n"
}
# mark it as exported
declare -fx echo_args

# run it with nohup
nohup bash -c 'echo_args "$@"' bash_ "an argument" "another argument"
#定义函数
echo_args(){
printf“”“$@”
printf“\n”
}
#将其标记为导出
声明-fx echo_参数
#用nohup运行它
nohup bash-c'echo_args“$@”bash_参数“另一个参数”

参数
bash
to
nohup
bash-c
子shell提供了一个“名称”;也就是说,它成为子shell中
$0
的值。它将被添加到错误消息(如果有的话)之前,因此我尝试使用一些有意义的东西。

您可以通过
nohup
调用
bash-c
(基本上与运行外部bash脚本相同)来使用函数(而不是别名)

为了使其正常工作,您需要将函数标记为导出的

# define the function
echo_args() {
  printf '<%s> ' "$@"
  printf "\n"
}
# mark it as exported
declare -fx echo_args

# run it with nohup
nohup bash -c 'echo_args "$@"' bash_ "an argument" "another argument"
#定义函数
echo_args(){
printf“”“$@”
printf“\n”
}
#将其标记为导出
声明-fx echo_参数
#用nohup运行它
nohup bash-c'echo_args“$@”bash_参数“另一个参数”

参数
bash
to
nohup
bash-c
子shell提供了一个“名称”;也就是说,它成为子shell中
$0
的值。它将在错误消息(如果有的话)前面加上前缀,因此我尝试使用一些有意义的东西。

不相关,但在文件上迭代的正确方法是
while read-r I;做done
这不是重复的,其他问题想在bash脚本中使用函数,我想知道如何在cli.script或命令行中实现它,这无关紧要
nohup
希望其参数是可执行文件,而不是shell函数。这使得这是另一个问题的重复。@kmassada您可以将其包装在shell脚本中。这是最好的解决方案,如果你需要这个工作。我认为这个问题很好,尽管可能是重复的。但是,您得到了解决方案…:)让您了解chepner和@hek2mglUnrelated,但是在文件上迭代的正确方法是
whileread-ri;做done
这不是重复的,其他问题想在bash脚本中使用函数,我想知道如何在cli.script或命令行中实现它,这无关紧要
nohup
希望其参数是可执行文件,而不是shell函数。这使得这是另一个问题的重复。@kmassada您可以将其包装在shell脚本中。这是最好的解决方案,如果你需要这个工作。我认为这个问题很好,尽管可能是重复的。但是,您得到了解决方案…:)给你车夫和@hek2mglooks不错:)。。不知道
declare-fx
看起来不错:)。。不知道
declare-fx