我正在编写一个脚本,该脚本从电子邮件中提取和保存 JPEG 附件并将它们传递给 imagemagick。但是,我住在德国,电子邮件文本/主题中的特殊字符“ö”、“ä”、“ü”和“ß”很常见。
我正在用 formail 提取主题:
SUBJECT=$(formail -zxSubject: <"$file")
Run Code Online (Sandbox Code Playgroud)
这导致:
(“Meine Güte”)甚至更糟
(“Schöne Grüße!”)。
我尝试将主题的一部分用作文件名和 imagemagick 文本注释,这显然不起作用。
如何在 bash 中将此 UTF-8 文本转换为带有特殊字符的文本?
提前致谢!马库斯
大家好
这是一个菜鸟问题,但我似乎无法在任何地方找到答案。其他函数如 'cut' 或 'awk' 或 'sed' 总是被提及但从未使用字符串表达式函数(我认为它被称为)
string="hi this is a string.and.it has no purpose other than being here"
searchstring="and"
temp=${string#*$searchstring} # this means everything after "and" will be inserted into temp
echo $temp = "hi this is a string."
Run Code Online (Sandbox Code Playgroud)
但是说我想要“和”之前的所有内容,并使用与我用来获取临时变量结果相同的方法,因此我想要
echo $temp = ".it has no purpose other than being here"
Run Code Online (Sandbox Code Playgroud)
我试过了
temp=${string%*$searchstring} (as I understand, # is from front and % is back)
Run Code Online (Sandbox Code Playgroud)
但这仅返回未更改的字符串内容
还有,手册页,这个叫什么,这个字符串表达式函数,在哪里可以找到更深入的信息?
bash: __bp_precmd_invoke_cmd: command not found即使在命令成功执行后,我在每个命令之后也会出现错误。
例如,如果我运行该ls命令,我会在列表后得到正确的目录列表,但会收到以下错误消息
bash: __bp_precmd_invoke_cmd: command not found
bash: __bp_interactive_mode: command not found
Run Code Online (Sandbox Code Playgroud)
所有其他命令都一样,命令运行得很好,但我总是在每个命令之后收到上面提到的错误。
如何摆脱它?我试过谷歌但无法解决它。
我想为我的服务器做一些简单的日志记录,这是一个在 Docker 容器中运行的小型 Flask 应用程序。
这是 Dockerfile
# Dockerfile
FROM dreen/flask
MAINTAINER dreen
WORKDIR /srv
# Get source
RUN mkdir -p /srv
COPY perfektimprezy.tar.gz /srv/perfektimprezy.tar.gz
RUN tar x -f perfektimprezy.tar.gz
RUN rm perfektimprezy.tar.gz
# Run server
EXPOSE 80
CMD ["python", "index.py", "1>server.log", "2>server.log"]
Run Code Online (Sandbox Code Playgroud)
正如你在最后一行看到的,我将 stderr 和 stdout 重定向到一个文件。现在我运行这个容器和 shell
docker run -d -p 80:80 perfektimprezy
docker exec -it "... id of container ..." bash
Run Code Online (Sandbox Code Playgroud)
并注意以下事项:
服务器正在运行,网站正在运行
没有 /srv/server.log
ps aux | grep python 产量:
root 1 1.6 3.2 54172 16240 …Run Code Online (Sandbox Code Playgroud) || :在 shell 脚本的上下文中是什么意思?
我刚刚遇到了这条线:
eval "/usr/bin/mybinary aparameter" || :
Run Code Online (Sandbox Code Playgroud) 试图让一个变量遇到一个长度不同的文本字符串。字符串中重要的部分是前几个字符。
var1=hello
if [ $var1 == hello ]; then
echo success
fi
Run Code Online (Sandbox Code Playgroud)
或者
var1=hello
if [ $var1 == h*o ]; then
echo success
fi
Run Code Online (Sandbox Code Playgroud)
输出:成功
但由于我关心前 3 个字符左右,这听起来合乎逻辑,但不起作用:
var1=hello
if [ $var1 == hel* ]; then
echo success
fi
Run Code Online (Sandbox Code Playgroud)
输出:-bash: [: 参数太多
由于我只关心前几个字符,我可以这样做:
var1=hello
if [ ${var1:0:3} == hel ]; then
echo success
fi
Run Code Online (Sandbox Code Playgroud)
那会起作用,但我正在寻找解释为什么我会收到该错误以及可能的更好的书面解决方案。
当我第一次安装并运行 Windows Linux 子系统时,控制台要求我为 bash 输入一个新的用户名。我输入User. 现在,当我在控制台中启动 bash 时,我的用户名和 PC 名称出现在提示的开头,例如
User@DESKTOP-TPQIRNP:/mnt/...
Run Code Online (Sandbox Code Playgroud)
如果我想更改 bash 控制台的用户名,我该怎么办?和电脑名称
bash windows-10 windows-subsystem-for-linux windows-10-v1607
我在我的 Mac 上使用 iTerm 并且我有一个我一直很舒服地使用的 .bash_profile。我最近了解了 fish bash 并将其安装在我的 Mac 上,突然间我的 .bash_profile 没有来源。关于为什么我看不到它的任何想法?
我如何指示我的 iTerm 和 fish 获取我的 .bach_profile ,就像以前没有鱼一样?
每当我在 Windows 10 Linux 子系统中使用 nano 编辑文件时,我都会遇到显示问题。
我将使用 Bash/SSH 连接到远程系统(Virtualbox 上的本地 CentOS7 VM)。然后,我将继续使用 nano 在所述远程系统上编辑文件。
我将打开一个文件,开始删除文本,突然间,整行文本开始消失。我必须关闭并重新开始我的工作。当我厌倦它时,我会切换到vim。我宁愿在 nano 中,这对我所做的基本工作很有效。
还有人看到这个吗?
编辑 #1
我正在使用 Fedora 25,并在我的 bash 配置文件中添加了以下别名:
alias releasenotes="dnf updateinfo --refresh info `dnf check-update | cut -d '.' -f 1 | xargs` | less"
Run Code Online (Sandbox Code Playgroud)
(我不能直接使用,dnf updateinfo info因为https://bugzilla.redhat.com/show_bug.cgi?id=1405191)
我的别名有效,但该命令大约需要 10 秒才能运行,并且由于 bash 在获取配置文件时解析和验证所有别名,因此创建新 shell 会导致 10 秒挂起。这很烦人。
有什么办法可以让 bash 不尝试解析和验证别名——或者只是那个?
bash ×10
linux ×2
windows-10 ×2
windows-subsystem-for-linux ×2
bash-alias ×1
bashrc ×1
docker ×1
email ×1
fish ×1
iterm ×1
logging ×1
mac ×1
redirection ×1
terminal ×1
utf-8 ×1
wildcards ×1