Open main menu

CDOT Wiki β

Changes

OPS245 Scripting Exercises dev

837 bytes added, 14:20, 14 January 2023
no edit summary
</pre>
== Getting input from the user === Bash user input ==In ULI101 you learned how to prompt the user for input and store it in a variable using the read command in Bash. There are two ways you can do this in Bash:
* The Prompt the user to enter their name using the '''echo''' command, then use the '''read ''' command to store it in basha variable:* <pre>echo "Please enter your name: "read name</pre> Do both in one line by using '''read''' with the '''-p''' option:<pre>read -p "Please enter your name: " name</pre> Either are correct. Which one you use is entirely up to your preference. == Python user input ==In Python, prompting a user for input works very similarly to the second method above (using '''read -p'''). To prompt a user for input we use the input() function . Prompt the user to input their name and store it in pythonthe variable name, using the input function:<pre>name = input("Please enter your name: ")</pre>
== Quotes ==