如何在两个单词之间按字母顺序检查哪些单词?例如在代码中
#!/bin/bash
var1="apple"
var2="bye"
if [ $var1 \> $var2 ]
then
echo $var1
else
echo $var2
fi
Run Code Online (Sandbox Code Playgroud)
我想要它打印苹果,因为苹果按字母顺序出现在bye之前,但它并没有按预期工作.我究竟做错了什么?
我知道这是相当基本的,但我仍然卡住了.所以我有一个需要接受变量n的函数,所以这是我的主要功能
int main(int argc, char* argv){
sort(argv[1]);
}
Run Code Online (Sandbox Code Playgroud)
而我正在调用这样的程序:
./sort 4 <text.txt
Run Code Online (Sandbox Code Playgroud)
但是数字4没有被识别或传递给函数.我究竟做错了什么?我知道argv [0]应该保存程序本身的名称,并且每个程序都应该保存参数.
I'm working on a project where I have to process the contents of a directory passed in as an argument, and I need to include invisible files (ones that start with .) as well. This is how I'm approaching it
#!/bin/bash
cd $1
for file in `dir -a -d * `;
do
#more code blah blah
Run Code Online (Sandbox Code Playgroud)
even though I use the -a tag on the dir command, it still ignores invisible files. Any ideas why?