Linux command [read]

read command

Read from standard input. One line is read from the standard input and the read contents are stored in the shell variable.

File(pra1.sh)Contents


#!/bin/bash

read -p 'Please enter the file name' fh
echo $fh

-p: Set user input information as standard input fh: Arbitrary variable name Standard input information is stored here $ fh: Display stored user input information

Execution result


$ ./pra1.sh
Please enter a file name Hello World
Hello World

Example of use

Reads the contents of the file string.txt and outputs it to standard output.

Contents of job definition script

Example of use


while read LINE
do
 echo "$LINE"
done     < string.txt

Recommended Posts

Linux command [read]
Linux command # 4
Linux command # 5
Linux command list
linux at command
[Linux] Search command
Linux [directory command]
Linux server command
Linux Command Summary
[Basic] linux command
Linux [shell command]
[Linux] Command / Knowledge
My linux command
Linux command <Basic 1>
Linux command collection
Linux mkdir command
Linux command basics
[Linux] Git command
Linux (command memory)
[Linux] Volume configuration command
Linux command cheat sheet
Linux command (sequential update)
Linux basic command memorandum
Linux command [File operation]
[Linux] Basic command summary
Linux command for self-collection
linux command error collection 1
Linux command line shortcut
linux sar command CPU usage
[Linux] tar.gz compression / decompression command
What is Linux? [Command list]
I read "Linux standard textbook"!
Read core voltage on Linux
Easy df command on Linux
Linux
Linux tar xz command memo
Linux Command Dictionary (for myself)
linux: create original Terminal command
[Note] Useful linux command collection
Linux command memorandum [for beginners]
Linux PC spec check command
[Linux] User / group command summary
[Infrastructure] Linux command, shell script collection
[Linux convenient command] Try inserting exa
Command to create Linux Live USB
[Linux] OS recovery with restore command
Completion of docker command on Linux
[Linux convenient command] Try inserting csview
Permission and ownership change command [Linux]
LINUX command [wc edition] Usage example
Linux command [ldconfig] LPIC learning memo
[linux] kill command to kill the process
Have python read the command output
[Linux convenient command] Try inserting bat
Linux command 16 procedure manual folder (completed)
Read Normal Linux Programming (Part 1 Only)
Linux command (basic in basic) personal memo
linux memorandum
Linux commands
Linux commands
Linux basics