handyla.blogg.se

Linux reader
Linux reader










If you’re writing a script and you want to capture user input, there is a read option to create a prompt that can simplify your code. Reminder: Variable names are case-senstive. You can use echo command to verify that the read command did its magic: read Linux_Handbook ↵ Here’s an example where I create the variable Linux_Handbook and assign it the value of the input. When you want to call the variable, you will use a $ in front of the name. When you declare the variable with read, you don’t need to do anything other than type the name of the variable. That might be fine if you have only one application in mind, but more than likely you’ll want to use your own variables.

linux reader

read ↵Īs I mentioned earlier, the $REPLY variable is built into read, so you don’t have to declare it. To make things easier to follow for the first example, I will use the ↵ symbol will show when the enter key is pressed. The system will capture input until you hit enter again.īy default this information will be stored in a variable named $REPLY. When you type read without any additional options, you will need to hit enter to start the capture. Now let’s see some examples of read command to understand how you can use it in different situations. By default, the command will create a variable to save that input to. When you use read, you are communicating to the bash terminal that you want to capture the input from the user. With almost every program or script, you want to take information from a user (input) and tell the computer what to do with that information (output). The scripts I am going to use here are very simple to understand and should be easy to follow, especially if you are practicing along with the tutorial. The read command can be confusing to get started with, especially for those who are new to shell scripting.

linux reader

I am going to write some simple bash scripts to show you the practical usage of the read command. In other words, if you want that your bash script takes input from the user, you’ll have to use the read command. The read command in Linux is a way for the users to interact with input taken from the keyboard, which you might see referred to as stdin (standard input) or other similar descriptions.












Linux reader