Questions tagged «bash»

与其他Bourne / POSIX shell相对,GNU的Bourne Again SHell特有的问题。对于一般关于Unix shell的问题,请改用/ shell标记。

2
在Bash中参数化对应用程序的链接调用
我在Bash shell中使用了一个黑匣子UNIX程序,该程序从stdin读取数据列,对其进行处理(应用平滑效果),然后输出到stdout。我通过UNIX管道使用它,例如 generate | smooth | plot 为了更加平滑,我可以重复进行平滑操作,因此可以从Bash命令行中调用它,如下所示: generate | smooth | smooth | plot 甚至 generate | smooth | smooth | smooth | smooth | smooth | smooth | smooth | smooth | smooth | smooth | plot 这变得越来越古怪。我想制作一个Bash包装器,使其能够通过管道传递smooth并将其输出直接反馈到smooth任意次数的新实例中,例如 generate | newsmooth 5 | plot 代替 generate | smooth …


2
退出具有正确关闭会话的快捷方式的shell(不键入exit)
我对每天使用的许多ssh会话使用ProxyJump命令,并且在这些会话上频繁切换用户,并且不得不exit连续键入3或4次并不是很有趣。 我知道newline+ ~+ .会终止ssh会话,我仍然必须检查它是否会像那样友好地终止它exit,但是如何用单个命令或快捷方式退出当前shell中的所有会话,例如键入exit3或4次就我而言变成一次性的东西?
12 bash  shell  session 


3
为什么“ cat {foo}”不输出foo,而是“ cat {foo,bar}”呢?
我试图在子文件夹中串联文本文件并尝试: cat ./{mainfolder1,mainfolder2,mainfolder3}/{subfolder1}/book.txt > out$var 但是,这没有返回任何内容。因此,尝试添加一个不存在的“ subfolder2” cat ./{mainfolder1,mainfolder2,mainfolder3}/{subfolder1,subfolder2}/book.txt > out$var 这次确实解决了,成功地将文件串联在一起。为什么会这样?

3
路径斜杠后的Bash括号扩展
我正在尝试使用大括号扩展名将文件复制到相同的目录中。我正在使用bash 4.4.18。 这是我所做的: cp ~/some/dir/{my-file-to-rename.bin, new-name-of-file.bin} 但是我得到这个错误: cp: cannot stat '/home/xyz/some/dir/{my-file-to-rename.bin,': No such file or directory 甚至像这样简单的括号扩展也会给我同样的错误: cp {my-file-to-rename.bin, new-name-of-file.bin} 我究竟做错了什么?


4
bash是否支持使用指针?
简单的问题。bash shell在编写shell脚本时是否支持使用指针? ${var[@]}在数组上进行迭代时,我对扩展符号很熟悉$var,但是目前尚不清楚这是利用指针在数组索引上进行迭代。bash是否像其他语言一样提供对内存地址的访问? 如果bash不支持使用指针,那么其他shell呢?
12 bash 


4
bash:使用空格安全的find到select程序
给定以下文件名: $ ls -1 file file name otherfile bash 本身与嵌入式空白完美配合: $ for file in *; do echo "$file"; done file file name otherfile $ select file in *; do echo "$file"; done 1) file 2) file name 3) otherfile #? 但是,有时我可能不想使用每个文件,或者甚至不想严格使用in $PWD,它是其中的find源。它也名义上处理空格: $ find -type f -name file\* ./file ./file …

1
如何复制文件夹中的所有文件(不包括正在写入的文件)?
我downloading通过HTTPie将多个文件下载到一个文件夹中。一个bash脚本旨在处理下载的文件,我尝试将下载的文件复制到另一个文件夹 find /folder/downloading -type f -exec mv '{}' /folder/downloaded \; 但这还会复制尚未完成的文件。我试图通过添加-mmin +5到命令来限制传输到较旧的文件。什么是有效的命令以使文件被写入而仅传输下载的文件?




3
如何在bash脚本中保存/ dev / stdout目标位置?
我有一个特定的bash脚本,它想要/dev/stdout在将第一个文件描述符替换为其他位置之前保留原始位置。 所以,自然地,我写了类似 old_stdout=$(readlink -f /dev/stdout) 而且它没有用。我很快就知道问题出在哪里: test@ubuntu:~$ echo $(readlink -f /dev/stdout) /proc/5175/fd/pipe:[31764] test@ubuntu:~$ readlink -f /dev/stdout /dev/pts/18 显然,$()它在子外壳中运行,并通过管道传输到父外壳。 因此,问题是:是否存在一种可靠的方法(范围仅限于Linux发行版之间的可移植性),以便将/dev/stdout位置另存为bash脚本中的字符串?

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.