相关疑难解决方法(0)

为什么`printf "%s"` 将以下两个字符串连接在一起?

$ printf "%s" a b
ab$ printf "%s%s" a b
ab
Run Code Online (Sandbox Code Playgroud)

我在理解printf. 如果我是对的,它与 C 编程语言中的字符串大致相同。

为什么格式说明符%s将以下两个字符串连接在一起?

为什么不 %s意味着只有一个字符串来替代它,而忽略剩余的字符串?

为什么两个字符串下%s和下%s%s的结果相同?

bash printf

10
推荐指数
2
解决办法
3615
查看次数

为什么 printf 打印出比预期更多的参数?

为什么这个 shell 脚本打印输入两次?

我希望脚本在 5 之后忽略输入。

脚本:

#! /bin/bash
echo "Enter 5 words : "
read  a b c d e 
printf "> %s %s %s %s %s <" $a $b $c $d $e
Run Code Online (Sandbox Code Playgroud)

输出:

user@linux:~$ pico ifs2.sh
user@linux:~$ ./ifs2.sh
Enter 5 words : 
1 2 3 4 5 
> 1 2 3 4 5 <user@linux:~$ ./ifs2.sh
Enter 5 words : 
1 2 3 4 5 6
> 1 2 3 4 5 <> 6     <user@linux:~$ ./ifs2.sh
Enter 5 words …
Run Code Online (Sandbox Code Playgroud)

shell-script

9
推荐指数
2
解决办法
2113
查看次数

标签 统计

bash ×1

printf ×1

shell-script ×1