如上。
基本上我想实现类似的东西
if not match then
do these things
else
do these other things
fi
谢谢
如上。
基本上我想实现类似的东西
if not match then
do these things
else
do these other things
fi
谢谢
我有这个非常简单的脚本:
#!/bin/bash
read local _test
echo "_test: $_test"
这是输出。
$ ./jltest.sh
sdfsdfs
_test:
我希望变量_test
仅是本地的。这可能吗?
_test=`shasum -a 256 my "file here.txt" | awk -F' ' '{print $1}'`
这按预期工作。但是我的强迫症想要使用类似的东西
_test="${my-command-here}"
但是由于 awk 部分中的单引号,我得到了一个错误的替换错误。
$ _test="${shasum -a 256 "my file here.txt" | awk -F' ' '{print $1}'}"
zsh: bad substitution
$ _test=${shasum -a 256 \"my file here.txt\" | awk -F\' \' \'{print $1}\'}
zsh: bad substitution
关于如何让它工作的任何想法?谢谢
我正在寻找与此 BASH 构造等效的 ZSH:
for file in *.{abc,def,ghi}; do #loop through all files with the extensions .abc, .def and .ghi
我找不到 ZSH 的类似结构。或者也许没有?
使用此运算符时,我的脚本出现错误。我有一些在线文档,双等号应该可以工作。有任何想法吗?
Zsh 参考指南:http: //zsh.sourceforge.net/Doc/Release/Conditional-Expressions.html
脚本:
#!/bin/zsh
if [ $_user == "root" ]; then
echo "root"
else
echo "not root"
fi
运行它:
$ ./script.sh
./script.sh:3: = not found
我认为最好用一个例子来完成
我的文件内容
name="apple" parameter1="value1" parameter2="value2";
name="orange" parameter1="value1" parameter2="value2";
name="tea" parameter1="value1" parameter2="value2";
name="whatever" parameter1="value1" parameter2="value2";
我想将 apple/orange/tea/whatever 转换为大写并将其保存回同一文件或新文件。
关于如何完成的任何想法?谢谢
编辑:
我有一个类似于下面示例的文本文件。
我要插入
<string>insert-me</string>
在指示的行。
我该怎么做?我尝试了与此类似的变体:
sed "/s/<key>first</key>/\n <array>/\n/test/g" test.txt
而且我不断收到“替代命令中的错误标志”错误。
谢谢
示例文本文件:
<record>
<key>first</key>
<array>
--I want to insert the line here--
<string>hello</string>
<string>world</string>
</array>
</record>
<record>
<key>second</key>
<array>
<string>its</string>
<string>me</string>
<string>again</string>
<string>hello</string>
<string>world</string>
<string>again</string>
</array>
</record>
我正在寻找一个像这样工作的“in”运算符:
if [ "$1" in ("cat","dog","mouse") ]; then
echo "dollar 1 is either a cat or a dog or a mouse"
fi
与使用多个“或”测试相比,这显然是一个更短的语句。