You can redirect the output of the echo command to a file using the > or >> operators. Here's how to do it:
- Using
>to create or overwrite a file:
echo 'Hello LabEx' > output.txt
This command will create a file named output.txt and write "Hello LabEx" to it. If output.txt already exists, its content will be overwritten.
- Using
>>to append to a file:
echo 'Welcome to LabEx' >> output.txt
This command will append "Welcome to LabEx" to the end of output.txt without overwriting the existing content.
You can check the contents of the file using the cat command:
cat output.txt
