I have this exactly as it says on #2 but I don't get any return command from bash firstscript.sh // is there a typo in the command provided or??? am I a Potatoe
Create and execute a simple Bash script.
Use the vim command to create the firstscript.sh file under your home directory.
[student@servera ~]$ vim firstscript.sh
Insert the following text, and save the file. The number of hash signs (#) is arbitrary.
#!/usr/bin/bash echo "This is my first bash script" > ~/output.txt echo "" >> ~/output.txt echo "#####################################################" >> ~/output.txt
Use the bash command to execute the script.
[student@servera ~]$ bash firstscript.sh
Potatoe Confirmed :// womp womp
The script doesn’t “return” text to the screen; instead, it redirects output into a file. That’s why you only see the result if you open the file with cat output.txt.
echo "" → prints an empty string (basically nothing).
>> ~/output.txt → appends that nothing as a newline to the file.
echo " "
echo prints whatever is inside the quotes.
"" is an empty string → so this prints nothing.
But echo always ends with a newline → so what actually gets sent is just a blank line.
>> ~/output.txt
>> means append to a file.
~/output.txt is the file in your home directory.
I guess I was expecting a return command... but the firstcript.sh is just putting the echo "this is my first bash script into output.txt
what is the meaning of "" >> ~/output.txt
The script doesn’t “return” text to the screen; instead, it redirects output into a file. That’s why you only see the result if you open the file with cat output.txt.
echo "" → prints an empty string (basically nothing).
>> ~/output.txt → appends that nothing as a newline to the file.
echo " "
echo prints whatever is inside the quotes.
"" is an empty string → so this prints nothing.
But echo always ends with a newline → so what actually gets sent is just a blank line.
>> ~/output.txt
>> means append to a file.
~/output.txt is the file in your home directory.
Potatoe Confirmed :// womp womp
Noted, I think I was misunderstanding what the bash command actually does
I reckon I thought it would print out the output as is
so bash runs the script, but the script itself was just adding/appending the syntax into output.txt
not sure why I thought bash would print out the script....
what ah marooon :///
You’ve understood it correctly now. Bash doesn’t print the script itself it executes each command inside it. In your case, those echo commands don’t print directly to the screen because their output is being redirected (> or >>) into output.txt. That’s why nothing appeared in the terminal, but the text showed up when you checked the file.
So think of it this way: bash runs the script, the script runs commands, and redirection decides where the output goes (screen or file). You’re definitely on the right track now. This is exactly how scripting works
@hedai710 The doubts that you had - thats exactly the kind of reasoning needed to truly understand a concept and make it stick in your mind forever!
now in your script, notice the two redirection symbols :
1. ">" which redirects output to a file, overwriting the file if it exists.
2. ">>" Appends output to a file, preserving existing content.
had you not use the output redirection , you would have got the expected output in your terminal.
Now I will modify your script a little bit to give you both the results - one that the course step wants and the other what you want :
The tee -a command appends the output to both the terminal and the file.
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.