我在互联网上看到了以下bash语句:
PYTHON_BIN_PATH=$(which python || which python3 || true)
Run Code Online (Sandbox Code Playgroud)
我明白,如果which python
失败,那么which python3
将被执行,但我不明白true
条件结束的目的.任何的想法?
嗨,我想删除一行中的最后一个逗号.例如:
输入:
This,is,a,test
Run Code Online (Sandbox Code Playgroud)
期望的输出:
This,is,a test
Run Code Online (Sandbox Code Playgroud)
我可以使用下面的命令删除最后一个逗号,如果它也是字符串的最后一个字符:(但这不是我想要的)
echo "This,is,a,test," |sed 's/,$//'
This,is,a,test
Run Code Online (Sandbox Code Playgroud)
如果在行中最后一个逗号后面有更多字符,则相同命令不起作用.
echo "This,is,a,test" |sed 's/,$//'
This,is,a,test
Run Code Online (Sandbox Code Playgroud)
我可以通过调用多个命令以脏方式实现结果,使用awk或sed正则表达式实现相同的任何替代方法?(这是我想要的)
echo "This,is,a,test" |rev |sed 's/,/ /' |rev
This,is,a test
Run Code Online (Sandbox Code Playgroud) 我试图在行的开头删除零,直到第四个字符.如果超过第4个位置发生零,则无需删除它.我无法正确实现这一目标.
01230 <------Delete 1 zero at start.
001230 <-----Delete 2 zeros at start.
0001230 <----Delete 3 zeros at start.
00001230<----Delete 4 zero at start.
000001230<---Delete 4 zero at start and leave 1, output 01230
1234560<-----Delete nothing.
Run Code Online (Sandbox Code Playgroud)
例:
cat file
0000abc0
00abcde0
0abcede0
00000abcede0
Run Code Online (Sandbox Code Playgroud)
abc0
abcde0
abcede0
0abcede0
Run Code Online (Sandbox Code Playgroud)
已经尝试过的事情:(当然没有帮助)
cat file |sed 's/^[0]//g' <----This just delete one zero at the start
000abc0
0abcde0
abcede0
0000abcede0
cat file | sed 's/^[0][0][0][0]//g'<---THis only works for line having 4 zeros.
abc0 …
Run Code Online (Sandbox Code Playgroud) 我陷入奇怪的问题。从bash脚本调用进程替换时,它不能工作,但是从终端拍摄时,它可以工作。
这是示例:在终端上运行时。
terminal>echo "$x"
a b c
d e f
g h i
j k l
terminal>echo "$y"
1
2
3
4
terminal>paste <(echo "$x") <(echo "$y") -d' '
a b c 1
d e f 2
g h i 3
j k l 4
Run Code Online (Sandbox Code Playgroud)
这是示例:示例脚本
#!/bin/bash
x='a b c
d e f
g h i
j k l'
y='1
2
3
4'
paste <(echo "$x") <(echo "$y") -d' '
Run Code Online (Sandbox Code Playgroud)
当我上面的脚本,我得到以下错误:
test: line 12: syntax error near unexpected token `(' …
Run Code Online (Sandbox Code Playgroud) 在以下目录结构中,我必须创建一个 zip 的“anisble”目录。这个想法是将 ansible 目录中的所有内容(如剧本、角色、库存详细信息和自定义模块)放入 zip 包中,并且其内容不应该对“ansible”目录之外的任何内容有任何依赖。
<home>
|<user>
|__ansible
|_____playbook.yml
|_____inventory/
| |____myHosts
|
|_____library/
| |___my_Custom_module.py
|_roles
| |____role1
|____role2
Run Code Online (Sandbox Code Playgroud)
我不能使用:“ /home/$USER/.ansible/plugins/modules/
”,因为这将使解决方案特定于用户,并且“ /usr/share/ansible/plugins/modules/
”位于ansible目录之外并且确实需要特权(该用户没有)
问题:
是否有任何可能的位置可以放置 my_custom_module.py 以便在运行时它会自动被 ansible 选择?这必须位于“ansible”目录内的某个位置。
如果我在运行 ansible playbook 之前执行此操作,它可以工作,但是在使用自定义模块之前是否可以通过 ansible playbook 以编程方式执行此操作?
导出 ANSIBLE_LIBRARY=library/my_custom_module.py
无论如何,我可以提供自定义模块相对于“ansible”目录的路径吗?在任何conf文件或环境变量中?请注意,我无法使用/etc ,/usr/ etc
. 所有内容都必须位于 ansible 目录内,
有可能吗?
这样列出了4个列表.我需要按照它排序first numerical column
.列由tabs
/ 分隔\t
.
France \t Paris \t 13.2 \t 14.2
Germany \t Munich \t Hamburg \t 16.9 \t 16.6
Norway \t 8.9 \t 9.1
Spain \t Barcelona \t Madrid \t Malaga \t 21.2 \t 19.4
Run Code Online (Sandbox Code Playgroud)
排序后,这些列看起来像 - >
Norway \t 8.9 \t 9.1
France \t Paris \t 13.2 \t 14.2
Germany \t Munich \t Hamburg \t 16.9 \t 16.6
Spain \t Barcelona \t Madrid \t Malaga \t 21.2 \t 19.4
Run Code Online (Sandbox Code Playgroud)
它们按照分类排序8.9, 13.2, …