我试图在bash程序中使用用户输入,但我认为我的代码是非常错误的

时间:2017-10-02 07:54:56

标签: bash input

我正在尝试使用用户的输入在OS X登录屏幕中设置消息,但它将消息设置为STRING,而不是实际消息。

在python中,例如将字符串声明为变量,这可以通过以下方式完成:

myString = str(input("Name your message")

我的问题;如何在bash中做同样的事情?我的代码:

#!/bin/bash
#User sets login message
echo Please name your input

#"text" to STRING?
declare STRING variable
STRING="Hello World"

#set message
sudo defaults write /Library/Preferences/com.apple.loginwindow LoginwindowText $STRING

#last output
echo you named the message $STRING

1 个答案:

答案 0 :(得分:0)

您可以使用“读取”命令。

re.compile(r'^(\d{1,3}(,\d{3})*)$')

参考:

  

http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_08_02.html

一旦你在一个变量中,你知道该怎么做。