我试图通过pid文件杀死进程:
kill -9 $(cat /var/run/myProcess.pid)
Run Code Online (Sandbox Code Playgroud)
pid文件包含进程号.但是执行kill不会给我带来任何标准输出并且进程仍然存在.但这有效:
kill -9 PID
Run Code Online (Sandbox Code Playgroud)
第一个kill命令有什么问题?是否无法从文件中提取PID?
pid文件的示例内容:
5424
Run Code Online (Sandbox Code Playgroud)
和
kill -9 5424
Run Code Online (Sandbox Code Playgroud)
作品.
我目前正在试用鱼壳而不是使用bash.我在学习鱼类等效符号方面遇到困难的一种符号$(command)
类似于此SOF帖子中的描述.我怎么用鱼写这个?请记住,我可以在我想要评估的命令周围使用反斜杠字符,但链接的帖子和其他帖子不鼓励这样做,因为它是评估命令的旧样式.
具体来说,这是我要转换为fish语法的bash命令(用于在shell启动期间初始化rbenv):
eval "$(rbenv init -)"
Run Code Online (Sandbox Code Playgroud) 我是制作bash脚本的新手,但我的目标是获取一个.txt文件,并将txt文件中的字符串分配给变量.我试过这个(如果我在正确的轨道上没有线索).
#!/bin/bash
FILE="answer.txt"
file1="cat answer.txt"
print $file1
Run Code Online (Sandbox Code Playgroud)
当我跑这个时,我明白了
Warning: unknown mime-type for "cat" -- using "application/octet-stream"
Error: no such file "cat"
Error: no "print" mailcap rules found for type "text/plain"
Run Code Online (Sandbox Code Playgroud)
我能做些什么来完成这项工作?
编辑**当我将其更改为:
#!/bin/bash
FILE="answer.txt"
file1=$(cat answer.txt)
print $file1
Run Code Online (Sandbox Code Playgroud)
我得到了这个:
Warning: unknown mime-type for "This" -- using "application/octet-stream"
Warning: unknown mime-type for "text" -- using "application/octet-stream"
Warning: unknown mime-type for "string" -- using "application/octet-stream"
Warning: unknown mime-type for "should" -- using "application/octet-stream"
Warning: unknown mime-type for "be" -- using "application/octet-stream"
Warning: …
Run Code Online (Sandbox Code Playgroud) 我很长时间以来都在试图逃避 bash 中的反引号。我尝试使用 \ 进行转义,但它不起作用。
bash 中是否可以逃避反引号?
I="hello.pdf"
var1=`cat <<EOL

\`\`\`sql
some code here
\`\`\`
EOL`
echo "$var1"
Run Code Online (Sandbox Code Playgroud)

```sql
some code here
```
Run Code Online (Sandbox Code Playgroud) 在手册中grep
,我们必须-o
打印--only-matching
图案。说echo foobar | grep foo
会返回foobar
,但添加-o
到grep
只会给foo
。
许多grep
选项(如-P
、-c
等)可以与 结合使用git
来搜索 Git 索引中的所有文件。但是,git grep -o PAT
会触发error: unknown switch
o'`。
如何只为 Git 索引中的每个文件打印匹配的字符串?即“ git grep -o PAT
”
我的审判:
for f in `git ls-files`; do grep -o PAT $f; done
Run Code Online (Sandbox Code Playgroud) 我正在编写一个程序来打印用户名和用户登录的次数,否则打印“未知用户”。
我的代码如下:
iden=$1
c='last | grep -w -c $iden'
if (( $c > 1 ))
then
echo "$iden $c"
else
echo "Unknown user"
fi
Run Code Online (Sandbox Code Playgroud)
我不断收到此错误:
-bash: ((: last | grep -w -c 123: 超出表达式递归级别(错误标记为“c 123”)
我想要一个 bash 脚本来识别调用者是否不在 git 标签上(但在未标记的分支上,例如)。我尝试了以下方法:
OUTPUT=$(git describe --exact-match --tags $(git log -n1 --pretty='%h')|grep "fatal:")
if [[ $OUTPUT != "0" ]]; then
echo "no tag present"
fi
Run Code Online (Sandbox Code Playgroud)
但no tag present
即使明显有标签并且打印出来的git describe --exact-match --tags $(git log -n1 --pretty='%h')
不包含fatal: ,我也会得到。为什么这不能按预期工作?
有什么区别
failed_instance=`aws deploy`
Run Code Online (Sandbox Code Playgroud)
和
failed_instance=$(aws deploy)
Run Code Online (Sandbox Code Playgroud)
我在说'和$(?