Questions tagged «bash»

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

3
如何使用for循环发现新行?
在网上的各个地方,我发现: \015 \012 \x0a - hex \n \r 全部作为各种换行符/回车符的同义词... 但是在这个小脚本中,我无法识别出遇到换行符的情况-有人可以告诉我我应该在if行中检查什么吗? #!/bin/bash test="this is a test" for a in "$test"; do if [[ "$a" == '\012' ]] ; then echo "FOUND NEWLINE" fi echo "$a" done
8 bash  shell  string 

3
重击字符串用一个替换多个字符
我从提要标题中将字母和数字以外的所有字符替换为破折号,以将结果用作任何文件系统的安全文件名: $ t="Episodie 06: No hope of riding home (NEW) - Advanced grammar" $ echo ${t//[^A-Za-z0-9]/-} Episodie-06--No-hope-of-riding-home--NEW----Advanced-grammar 但是我想将所有重复的破折号压缩成一个 Episodie-06-No-hope-of-riding-home-NEW-Advanced-grammar 我发现我可以使用两遍替换来实现: $ t="Episodie 06: No hope of riding home (NEW) - Advanced grammar" $ tmp=${t//[^A-Za-z0-9]/-} $ echo ${tmp//--/-} Episodie-06-No-hope-of-riding-home-NEW--Advanced-grammar 我以为我可以像这样通过一个步骤: $ echo ${t//[^A-Za-z0-9]+/-} 但这不起作用。 有什么线索吗? 注意:我不想使用sed或其他工具
8 bash  shell  string 

1
如何在Bash中修复字符编码(Arch Linux)
我在bash中使用德国变音符号编码时遇到一些问题。它通常工作正常,但是当我键入无效命令时,bash生成的错误消息包含奇怪的转义序列,而不是实际字符。 这是显示问题的日志: [root@myhost ~]# mkdir ä [root@myhost ~]# ä -bash: $'\303\244': Kommando nicht gefunden. [root@myhost ~]# ü -bash: $'\303\274': Kommando nicht gefunden. [root@myhost ~]# ls ä äöü Projects tbb [root@myhost ~]# cat äöü äüö [root@myhost ~]# rm ä rm: Entfernen von „ä“ nicht möglich: Ist ein Verzeichnis [root@myhost ~]# rmdir …

4
Bash将其提示写入哪个流?
我正在尝试将bash的所有输出(提示,用户输入,结果)重定向到文件 例: /bin/bash > file.txt 2>&1 我以为可以,但是没有得到提示。谁能告诉我我在做什么错?

2
重击颜色输出失败
是sed还是echo问题?我做错了什么? $> cat ~/bin/color_test.sh #!/bin/bash ColorOff='\e[0m' # Text Reset BWhite='\e[1;37m' # Bold White string="test TEST test" echo -e "$string" | sed -e "s/TEST/${BWhite}TEST${ColorOff}/g" $> ~/bin/color_test.sh test e[1;37mTESTe[0m test 期望以粗体突出显示TEST。
8 bash  sed  quoting 


1
Bash:`-su:$ *:绑定变量`set -u`
这是运行GNU bash 4.0版的FreeBSD 7.x系统。 在Bash中,该set -u选项可以强制Shell如果遇到未设置的变量,则打印错误,如下所示: $ set -u $ echo $THISISUNSET -su: THISISUNSET: unbound variable $ echo $? 1 但是,我也遇到$ *的相同错误: $ echo $* -su: $*: unbound variable $ echo $? 1 $ echo $@ -su: $@: unbound variable Bash手册4.3.1 Set Builtin专门说set -u忽略$ *和$ @: -u在执行参数扩展时,将除特殊参数'@'或'*'之外的未设置变量和参数视为错误。错误消息将被写入标准错误,并且非交互式外壳将退出。 我怎样才能解决这个问题?
8 bash  freebsd 

2
了解重定向的顺序
如果将多个重定向一起使用,更改顺序会有所不同吗? 人们将如何理解其命令的含义?是从左到右还是从右到左读取重定向而建立的重定向链接的通道? 例如 command 2>&1 > somefile command > somefile 2>&1 谢谢并恭祝安康!


3
通过脚本或Nautilus菜单仅递归chmod文件夹或文件?
这已经在这里讨论过了。 我想知道的是如何改变这些: 仅此文件夹中的递归chmod文件: find . -type f -exec chmod 0600 {} \; 仅此文件夹中的递归chmod文件夹: find . -type d -exec chmod 0755 {} \; 到bash脚本中,因此可能类似于: 对于文件: rchmodf 744 . 对于目录: rchmodd 755 . 并且...如果可能的话,还可以放入鹦鹉螺右键菜单选项。
8 bash  nautilus  chmod 


5
文件顶部时查找不递归
想象一下一个源代码树。到处都有xml文件。 但是,由于在该树的根目录下有一个XYZ.xml,因此找不到我的xml文件。 find -iname *.xml 退货 ./XYZ.xml 代替 ./XYZ.xml ./a/b/c/bob.xml ./b/d/top.xml
8 bash  find  recursive 


2
使用exiv2打印特定的Exif图像数据值
如何使用exiv2之类的工具打印图像Exif日期? 我的目标是将图像的年和月写到单独的变量中。我是否真的必须用正则表达式解析输出,还是有类似这样的替代方法: exiv2 DSC_01234.NEF -ps | grep 'Image timestamp' | ...regex to parse the date

2
bash 4有哪些新功能?
到目前为止,我一直在使用bash3,只是得到了最新版本的副本 $ ./bash --version GNU bash, version 4.1.0(1)-release (i686-pc-linux-gnu) Copyright (C) 2009 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. $ 与版本3相比,版本4的主要更改/功能有哪些?
8 shell  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.