Questions tagged «shell»

Shell是Unix的命令行界面。您可以交互地在外壳程序中键入命令,也可以编写脚本来自动执行任务。使用此标记可解决适用于/ bin / sh和大多数兼容shell(ash,bash,ksh,zsh等)的问题。对于有错误的Shell脚本,请在此处发布之前在http://shellcheck.net中对其进行检查。

3
如何用xargs引用参数
假设我要删除文件夹中大于1 MB的所有文件。 $ find . -size +1M | xargs -0 rm 这不会删除名称中带有空格的文件。因此,我希望它引用发送给的所有参数rm。如果find给出,Some report.docx则应传递"Some report.docx"给rm。 我怎样才能做到这一点?
15 shell  find  quoting  rm  xargs 

3
如何将已经转发的ssh密钥转发到tmux?
我正在从存储密钥的计算机通过SSH连接,然后转发到第二台计算机,然后尝试从tmux中使用密钥。输入tmux时,我似乎“松开”了转发。如何“再次转发”以便我可以在tmux中使用我的密钥? $ ssh [server] -o ForwardAgent=yes $ git pull # Succeeds. $ /bin/bash $ git pull # Still succeeds, despite new shell. $ exit $ tmux attach $ git pull # Permission denied (publickey)
15 shell  ssh  tmux 

4
Ctrl-C与bash中的两个同时命令
我想在Linux机器上的bash中同时运行两个命令。因此,在我的./execute.shbash脚本中,我输入: command 1 & command 2 echo "done" 但是,当我想停止bash脚本并按Ctrl+时C,仅第二个命令停止。第一个命令保持运行。如何确保完整的bash脚本已停止?或者在任何情况下,如何停止两个命令?因为在这种情况下,无论我多按一次Ctrl+ C,命令都会继续运行,并且我不得不关闭终端。

2
GLOBIGNORE如何运作?
根据bash的手册页: GLOBIGNORE A colon-separated list of patterns defining the set of filenames to be ignored by pathname expansion. If a filename matched by a pathname expansion pattern also matches one of the patterns in GLOBIGNORE, it is removed from the list of matches. 但是在实践中... $ bash --noprofile --norc bash-4.2$ touch …

3
Shell脚本-意外令牌'else'附近的语法错误
使用以下shell脚本,为什么我会出错 syntax error near unexpected token `else' Shell脚本 echo "please enter username" read user_name echo "please enter password" read -s pass echo ${ORACLE_SID} SID=${ORACLE_SID} if ["${ORACLE_SID}" != 'Test'] then sqlplus -s -l $USER_NAME/$PASS@$SID <<EOF copy from scott/tiger@orcl insert EMP using select * from EMP exit EOF else echo "Cannot copy" …

3
如何处理bash管道中的原始二进制数据?
我有一个bash函数,该函数将文件作为参数,验证文件是否存在,然后将标准输入中的所有内容写入文件中。天真的解决方案适用于文本,但我在使用任意二进制数据时遇到问题。 echo -n '' >| "$file" #Truncate the file while read lines do # Is there a better way to do this? I would like one... echo $lines >> "$file" done
15 bash  shell  binary 

2
将命令行参数传递给Shell脚本中的程序
至于./script.sh arg1 [arg2 arg3 ...],命令行参数arg1,arg2......可以得到通过$1,$2...,但是参数的数目是不固定的。 在shell脚本中,我想将参数从arg2传递给程序, #/bin/bash ... /path/to/a/program [I want to pass arg2 arg3 ... to the program] ... 由于可能存在一个或多个参数,我该怎么办?

5
用bash索引字符串
如何在sh / bash中按索引引用字符串?也就是说,基本上将其拆分。 我正在尝试删除文件名的5个字符。所有名称都具有以下结构:name_nr_code。我正在尝试删除5个字母数字代码位。name_nr_始终为10个字符。 有没有类似的事情? for i in * ; do mv "$i" "$i"[:10] ; done
15 bash  shell  string 

2
如何使用grep和sort命令进行排序?
我想创建一个在文件中找到的所有TCP服务的排序列表,/etc/services将命令的输出通过管道传递grep tcp /etc/services到命令中sort,然后将该管道的输出重定向到文件中~/pipelab.txt。 我不断收到一条错误消息,指出我的输出是错误的,我也不知道为什么。 这是我最后尝试过的: grep tcp /etc/services > ~/pipelab.txt | sort
15 shell  pipe 





3
ping -w和ping -W有什么区别?
什么是-w中(截止日期)标志ping呢?我无法在ping手册页中找到它的描述。仅用于-W,需要几秒钟作为参数。它们之间有什么区别,如何将ping超时(如果主机没有响应)设置为200ms?
15 shell  ping  timeout 

1
如何隐藏Linux shell中键入的命令?
有没有一种方法可以隐藏我在外壳程序中输入的内容,以便终端不回显我的按键,同时仍保留命令的输出? 例如,如果我运行ip addr show,则屏幕上唯一的东西应该是该命令的输出-而不是我键入的“ ip addr show”。

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.