我正在尝试根据从父 shell(即 bash)继承的值来设置TERM我的 tmux 会话的环境变量。请注意,我的文件中有以下行,因此实际上会被继承:.tmux.confTERM.tmux.confTERM
set -g update-environment '...some variables... TERM'
Run Code Online (Sandbox Code Playgroud)
基本上,TERM在xterm-256color父 shell 中,我检测到并default-terminal使用以下命令设置选项:
if "[[ ${TERM} =~ 256color ]]" 'set -g default-terminal screen-256color'
Run Code Online (Sandbox Code Playgroud)
该行在我的工作 PC (RHEL 6.6) 上的 tmux 1.9a 中工作,并正确设置TERM为screen-256color,但在其他 PC 上(包括运行 tmux 1.8 的工作 Ubuntu PC 和运行 tmux 2.1 的家用 Ubuntu PC),“condition”命令始终似乎返回 false,因此TERM仍在screen新的 tmux 会话中。
我也尝试过这样做if 'true' 'set -g default-terminal screen-256color',但这也不起作用!(TERM仍在screen新的 …
我有以下目录结构。
drwxr-xr-x 5 ec2-user ec2-user 4096 May 22 07:03 TEEST
drwxr-xr-x 5 ec2-user ec2-user 4096 May 24 05:33 BEE-TES
drwxr-xr-x 5 ec2-user ec2-user 4096 May 24 10:53 ONE
drwxr-xr-x 5 ec2-user ec2-user 4096 May 25 09:50 TWO
lrwxrwxrwx 1 ec2-user ec2-user 28 May 25 09:50 previous -> TWO
drwxr-xr-x 5 ec2-user ec2-user 4096 Jun 1 11:00 TEMP
lrwxrwxrwx 1 ec2-user ec2-user 28 Jun 1 11:00 current -> TEMP
Run Code Online (Sandbox Code Playgroud)
如何删除除符号链接指向的目录之外的所有目录?
所以我试图为我的树莓派创建一个安装脚本,第一件事是给它们一个静态IP。
echo -e "Enter static IP"
read static_ip
echo -e "Enter DNS IP"
read dns_ip
echo -e ""
echo -e "The following settings will be set"
echo -e "\e[32mStatic IP:\e[0m\t${static_ip}"
echo -e "\e[32mDNS IP:\e[0m\t${dns_ip}"
sudo echo "interface wlan0" >> /etc/dhcpcd.conf
sudo echo "static ip_address=${static_ip}/24" >> /etc/dhcpcd.conf
sudo echo "static routers=${dns_ip}" >> /etc/dhcpcd.conf
sudo echo "static domain_name_servers=${dns_ip}" >> /etc/dhcpcd.conf
Run Code Online (Sandbox Code Playgroud)
但它一直说“权限被拒绝”,我想知道我在这里做错了什么?
正如标题所说:
如何使用file命令(直接)读取vmlinuz版本?
使用:file /vmlinuz | grep version,
它必须这样显示4.11.0-9.1-liquorix-amd64。
我正在玩 Bash 脚本。我想将命令的结果分配给一个变量,并将其返回代码分配给另一个变量。
前任。:
line_count=$(cat "$filename" | wc -l) #If the file does not exist, an error code is returned
cmd_return_code=$? #I want to assign the previous error code to a variable
Run Code Online (Sandbox Code Playgroud)
我尝试如上所示使用$?,但它捕获了前一个赋值本身的返回码,即 0。
我怎样才能做到这一点?
谢谢
编辑:既然我得到了答案,我标记了@KamilMaciorowski 的一个更适合标题的答案,但@oliv 的这个答案实际上更适合我的主要目的的实际需要。(在 awk 上一致地处理带中断的 csv 文件。)
因此,如果您在类似的情况下寻找 awking,我建议您先检查一下!
请帮我准备几千个 csv 文件以供awk处理!某些字段在字段内有换行符,这导致将awk它们作为多个记录进行处理。然而,这些有问题的换行符只发生在插入 ^M 的地方,所以我只需要从所有这些换行符中完全删除 ^M 和换行符。
*这些^Ms 确实是换行符,而不是文字插入符和字母 M 字符串。该文件是为 .net 解析和处理而生成的,但我没有在文件生成/读取端开发应用程序,所以我真的不知道它是如何成功解析的。它专门用于某些列中具有多行字符串(注释)的字段。
那么如何制作这个(带有 1 个标题和 2 个记录的 csv。某些字段中有换行符,前面有 ^M):
"header_1", "header_2", "header_3"
"1-1", "1-2", "1-3"
"2-1", "2-2_a^M
2-2_b^M
2-2_c", "2-3"
Run Code Online (Sandbox Code Playgroud)
像这样?(带有 1 个标题和 2 个记录的 csv,每个记录中都没有换行符。):
"header_1", "header_2", "header_3"
"1-1", "1-2", "1-3"
"2-1", "2-2_a2-2_b2-2_c", "2-3"
Run Code Online (Sandbox Code Playgroud)
我尝试删除它们,sed但我听说没有办法处理,而且我不太明白原因。
for file in *.csv; do
sed -e "s/^M//" $file > sedded/$file;
done …Run Code Online (Sandbox Code Playgroud) 当变量用引号引起来时,是否可以使用 HEREDOC 并进行变量扩展?
示例:$package 是在脚本运行之前设置的环境变量
#!/bin/bash
cat > out.json <<'EOF'
{
"apps": [
{
"cwd":"/usr/local/$package"
}
}
EOF
Run Code Online (Sandbox Code Playgroud)
如果 $package="www" 则预期输出
{
"apps": [
{
"cwd":"/usr/local/www"
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用以下链接:
https://help.github.com/en/articles/generate-a-new-ssh-key-and-adding-it-to-the-ssh-agent
当我复制并粘贴:$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com",在引用中替换我自己的 github 电子邮件时,我收到错误。
这是我粘贴的内容和收到的错误:
$ $ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
bash: $: command not found
Run Code Online (Sandbox Code Playgroud)
谁能帮我吗?
如果我有:
for i in *.mov;
do
ffmpeg -y -i $i -c:v copy -c:a copy ${i%%.mov}.mp4
done
Run Code Online (Sandbox Code Playgroud)
这运行良好。但如果我跑:
find . -name "*.ts" -print0 | while read -d $'\0' file;
do
ffmpeg -i "$file" -c copy -map 0 "${file%%.ts}_rec.mp4";
done
Run Code Online (Sandbox Code Playgroud)
这失败了。我需要输入-nostdin。
find . -name "*.ts" -print0 | while read -d $'\0' file;
do
ffmpeg -nostdin -i "$file" -c copy -map 0 "${file%%.ts}_rec.mp4";
done
Run Code Online (Sandbox Code Playgroud)
文档解释说,这会禁用标准输入上的交互,并且对后台进程很有帮助。
为什么在第二种情况下 FFmpeg 是后台进程?或者还有其他问题吗?
键入Ctrl+D会按预期退出 bash shell,但仅当命令行为空时才有效。当在命令行上输入某些内容时,它会被执行,就像Enter被按下一样。有没有办法让它永远退出?