Question: I'm very new to Linux. The instructions that were given to me were: Recall the Linux command that lists the contents of your directory
I'm very new to Linux. The instructions that were given to me were: "
-
Recall the Linux command that lists the contents of your directory - the basic command without flags. Create a shell variable called second_var to be equal to the output of this command.
-
Write a loop that then appends the values of this variable one item per line to the output_bash.txt file.
I first created a shell variable called second_var to be equal to the output of the ls command. To do this I wrote second_var=$ (ls),. When I write echo $second_var, the output of the command ls is shown in the terminal. Now I need to write a loop that then appends the values of this variable (second_var) one item per line to a certain text file(output_bash.txt). As in, I need to append the files from a particular directory to a certain text file ending .txt. So far I have :
for i in /home/hpc-learner/projects/week1-bash/bash_workdir; do print $second_var done >> output_bash.txt
I know that this is not correct, however, I am unsure of how to create the loop.
Thanks in advance, and any help is appreciated.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
