Most of the time you don't have to write your own, but see if you can read it together and see an example of less than 10 lines.
#!bin/bashgetcontent () {if [!-e $]; then return 1;fi content= ' cat $ ' echo ${content//root/h2do}}getcontent/etc/h 2doecho $?getcontent/etc/passwd
Line 1th: Select Bash to interpret subsequent scripts;
Line 2nd: function declaration;
Line 3rd: The reserved variable is used to represent the first parameter, the first parameter is the file path, determine whether the file exists, if there is no function directly return;
Line 4th: Use the cat command to store the contents of the file in variable content;
Line 5th: Output the content variable, while replacing all the root in the contents with h2do by regular, the variable is replaced by one/time only once, two//replace all;
Line 7th: Function call, use a nonexistent file;
Line 8th: Output the previous command to return the result;
Line 9th: Function call, use an existing file;
We need to know a little shell script.