Bash Read File
Bash Read File – To read a file in Bash Scripting, you may use cat command or use “<” to open file and attach it to a standard input device handle of some application. In this Bash Tutorial, we shall present you with syntax and examples to read a file.
Example : Bash Read File using – cat fileName
Syntax
</>
Copy
value=`cat FileName`
Sample File
Learn Bash Scripting.
Welcome to TutorialKart!
Learn Bash with examples.
Bash Script File
</>
Copy
#!/bin/sh
value=`cat sampleFile.txt`
echo "$value"
$ ./read-file-example
Learn Bash Scripting.
Welcome to TutorialKart!
Learn Bash with examples.
Example : Bash Read File using – $(<fileName)
Syntax
</>
Copy
value=$(<FileName)
Bash Shell
~/workspace/bash/file$ value=$(<sample.txt)
~/workspace/bash/file$ echo $value
Learn Bash Scripting.
Welcome to TutorialKart!
Learn Bash with examples.