Questions tagged «shell»

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


5
匹配模式时如何在行尾添加文本?
输入: line1 with the PATTERN that contains ( ) line2 with the PATTERN that contains ( ) lineN with the PATTERN that contains ( ) 输出: line1 with the PATTERN that contains ( ) ; line2 with the PATTERN that contains ( ) ; ... lineN with the PATTERN that …

1
可以将stdout和stderr重定向到同一文件行吗?
我读过的重定向时stdout和stderr同一个文件使用2>&1,stdout通常,嵌段缓冲,而stderr不是缓冲。 如果将很长的行写入stdout,需要两次单独的缓冲区刷新,stderr中间发生滑动的行会发生吗?像这样: stdout: aaaaaaaa.....really long line......aaaaaaaaaaaa<newline> stderr: eee<newline> combined: aaaaaaaaaaaaaaaaeee<newline> aaaaaaa<newline>

3
是否可以通过编程方式更改父Shell的工作目录?
我想编写一些代码以允许我切换到通常访问的某些目录。说这个程序是mycd,并且/a/very/long/path/name是我要转到的目录。 所以我可以简单地键入mycd 2而不是cd /a/very/long/path/name。在这里我假设mycd知道2是指/a/very/long/path/name。也可能有mycd 1,mycd 3,...等等。 问题是我必须编写mycd为shell脚本并键入. mycd 2以执行所需的操作,因为否则该脚本将在子脚本中执行,而子脚本不会更改我实际上关心的父shell。 我的问题是: 我可以不用使用它source吗?因为. mycd假定mycd必须是一个shell脚本,并且这可能还会引入一些我不需要的功能。 我可以用其他一些编程语言实现它吗?

3
&&和;和有什么区别?什么时候分叉睡觉到背景?
我刚刚问了一个有关在后台中休眠的过程的问题。 我自己想到的符号如下所示: sleep 10 && echo "hello world" & 这个对不同问题的答案使用了不同的格式。 ( sleep 10 ; echo "hello world" ) & 我知道,&&如果第一个过程返回true ,则仅允许第二个过程开始。睡眠会失败吗?有没有一种情况我应该优先选择另一种情况?

2
查找源shell脚本的位置
源shell脚本是否可能知道其位置?我已经阅读了确定源shell脚本的路径,但是答案集中于bash,tcsh如果使用POSIX shell,则失败。$0也不是解决方案,并且会产生错误的结果。 解决方案不需要100%可靠。该路径不太可能包含硬链接或符号链接。 # sourcing the script should yield the absolute path to the script . somedir/thescript # within “thescript” -> /tmp/foo/bar/somedir 背景知识:该脚本是现有应用程序的一部分,该应用程序在bin相对于源脚本的已知位置(每个体系结构有所不同)的目录中包含数十个二进制文件。要使用该应用程序,用户需要获取将bin目录添加到的脚本PATH,以便可以在当前外壳程序(可能是任何一个外壳程序)中轻松调用应用程序的二进制文件。
8 shell  path 

2
“ cd&”是什么意思?
我知道如何通过键入从终端更改目录 cd <directory> 但是这是场景。我正在使用终端进入git存储库的文件夹。 glenn存储库 glenn-remdroid存储库 给定上面的文件夹结构,我想进入,glenn-remdroid-repository因为这是我的存储库。 cd glennRepositories 在切换到glenn-remdroid-repository之前,我错误地键入了命令 cd & 代替cd *。我cd *之所以使用该文件夹,是因为该文件夹名对我来说太长了,抱歉。 当我执行时cd &,终端回复 [1] 7519 当我执行cd *这件事时 [1]+ Done cd (wd: ~/glennRepositories) (wd now: ~/glennRepositories/glenn-remdroid-repository) 有谁代表什么cd &及其输出?Google不知道我的问题:)

6
如何在不要求覆盖的情况下复制或移动文件?
我尝试过的 root@host [/home1]# cp -f hello /home3 cp: omitting directory `hello' root@host [/home1]# cp -rf hello /home3 cp: overwrite `/home3/hello/.buildpath'? y cp: overwrite `/home3/hello/.bash_logout'? y cp: overwrite `/home3/hello/.project'? ^C 他们总是问我是否要覆盖。使用mv也不起作用。所以我该怎么做? 我尝试过的其他方法: root@host [/home1]# cp -rf hello /home3 cp: overwrite `/home3/hello/.buildpath'? y cp: overwrite `/home3/hello/.bash_logout'? y cp: overwrite `/home3/hello/.project'? ^C root@host …
8 shell  alias  cp 


1
使用终端的自动完成路径功能输入到Shell脚本
我想编写一个脚本,该脚本是:(1)获取一个路径,使用户能够使用制表符自动完成,然后(2)从用户获取文件名,然后(3)在该路径下创建一个扩展名为的文件。文本文件。 我的问题是:我该怎么办1.?我如何告诉bash要求输入“自动完成”路径,最好是部分路径(例如〜/ x /)已默认填充? 注意:路径几乎总是包含空格。


2
Linux支持通过SSH同时登录多少用户?
我知道Linux支持同时登录多个用户。 但是,可以同时登录Linux的最大用户数量是多少? 我看到有有69个tty文件(ttyn或ttysn,其中n是一个整数,比如tty0,tty1,tty2...)在我的/dev目录中。我认为这些文件是外壳。因此,我认为该Linux系统仅支持同时登录的69位用户。 我的想法正确吗?如果我的假设是错误的,请说明Linux的用户限制,包括如何实现。 另外,如何访问已登录用户的详细信息?我知道命令w,谁,但是我正在寻找复杂的工具。
8 linux  shell  ssh  login  limit 


2
[[$ variable]]和[[-n $ variable]]之间的区别?
用bash表示,[[ $variable ]]并且[[ -n $variable ]]完全等效吗?从下面的输出来看,似乎是这种情况,但是我看到两种用法都在shell脚本中很普遍。 $ z="abra" $ [[ $z ]] $ echo $? 0 $ [[ -n $z ]] $ echo $? 0 $ z="" $ [[ $z ]] $ echo $? 1 $ [[ -n $z ]] $ echo $? 1 $ unset z $ [[ $z …
8 bash  shell  test 

1
Bash脚本不读取输入
我有一个脚本,该脚本应该在后台运行命令,并且可以执行该命令。问题在于,当脚本执行读取命令时,它不会暂停并接受输入。这里是: printf "Where is yo music?: " read musicPath cd $musicPath ls | while read currentSong;do seconds=`mdls "$currentSong"|sed -n '20p'|awk '{print $3}'|cut -d. -f1` hours=$((seconds / 3600)) seconds=$((seconds % 3600)) minutes=$((seconds / 60)) seconds=$((seconds % 60)) echo "Song: $currentSong" echo "Length: $hours:$minutes:$seconds" afplay "$currentSong"& printf "yes (y), no (n), or …

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.