[centos@localhost bin]$ show123-2.sh 3
This program will print your choice
Your choice is
3
[centos@localhost bin]$
function printit(){
echo -e "Your choice is "
}
echo -e "This program will print your choice\n"
case $1 in
"1")
printit;echo -e "$1"
;;
"2")
printit;echo -e "$1"
;;
"3")
printit;echo -e "$1"
;;
*)
echo -e "You just have three choices that is 1 2 3."
exit 1
;;
esac
exit 0
为什么Your choice is 3,is 和3之间有个回车呢?
能否去掉这个回车?
```bash
```
因为函数调用再加echo会换行的~~所以你的结果会换行
能否去掉这个回车?可以,很简单~~加一个 -n 参数就可以,脚本如下
#!/bin/bash
function printit(){
echo -e -n "Your choice is "
}
echo -e "This program will print your choice\n"
case $1 in
"1")
printit;echo -e "$1"
;;
"2")
printit;echo -e "$1"
;;
"3")
printit;echo -e "$1"
;;
*)
echo -e "You just have three choices that is 1 2 3."
exit 1
;;
esac
exit 0