小编use*_*080的帖子

Shell脚本 - 哪个词首先按字母顺序排列?

如何在两个单词之间按字母顺序检查哪些单词?例如在代码中

#!/bin/bash

var1="apple"
var2="bye"

if [ $var1 \> $var2 ]
then
echo $var1
else
echo $var2
fi
Run Code Online (Sandbox Code Playgroud)

我想要它打印苹果,因为苹果按字母顺序出现在bye之前,但它并没有按预期工作.我究竟做错了什么?

bash shell alphabetical

4
推荐指数
1
解决办法
3917
查看次数

将参数传递给main

我知道这是相当基本的,但我仍然卡住了.所以我有一个需要接受变量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]应该保存程序本身的名称,并且每个程序都应该保存参数.

c program-entry-point

1
推荐指数
1
解决办法
8879
查看次数

Shell scripting- processing hidden files

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?

bash shell file

0
推荐指数
1
解决办法
720
查看次数

标签 统计

bash ×2

shell ×2

alphabetical ×1

c ×1

file ×1

program-entry-point ×1