Outputs the method that you often use for one of the Linux commands, the echo command.
This is a command that can do something like this.
--Display of character string on the screen --Display of command execution result --Output the string to a file --Add character string to file
Displays the specified character string.
command
echo "String"
Execution example
[root@tspweb01 test]# echo aaaaa
aaaaa
Displays the command execution result.
command
echo $?
--Command execution result
Execution result | Contents |
---|---|
0 | True(Command execution successful) |
1 | False(Command execution failed) |
127 | Command not found |
--True (success)
Execution example(True)
[root@tspweb01 test]# true
[root@tspweb01 test]# echo $?
0
--False
Execution example(False)
[root@tspweb01 test]# false
[root@tspweb01 test]# echo $?
1
--Command not found
Execution example(Command not found)
[root@tspweb01 test]# wh
-bash: wh:Command not found
[root@tspweb01 test]# echo $?
127
[root@tspweb01 test]#
Outputs the specified character string to a file.
command
echo "String" >file name
Execution example
[root@tspweb01 test]# echo "testtest" > test.txt
[root@tspweb01 test]# cat test.txt
testtest
[root@tspweb01 test]#
Adds the specified character string to the file.
command
echo "String" >>file name
[root@tspweb01 test]# cat test.txt
testtest
[root@tspweb01 test]# echo "testtest" >> test.txt
[root@tspweb01 test]#
[root@tspweb01 test]# cat test.txt
testtest
testtest
[root@tspweb01 test]#
Please be careful not to confuse >
with >>
during actual work.
(The meaning is completely different.)
-->
: Overwrite the entire file
-->>
: Add one sentence to the last line of the file
Be sure to use the cp
command to make a backup when working on important files.
You can do this with the echo command.
--Display of character string on the screen --Display of command execution result --Output the string to a file --Add character string to file
How about applying it to a bash script?
Detailed summary of echo commands [Linux command collection] Unexpectedly convenient command true / false
Recommended Posts