@harshit_rwt there is an error in the firstscript.sh file, It will not create 5 files (at least for me) instead it will create only 1 file with the name file_{1..5}.txt.
The below code works fine:
# Correct way to create the files:for i in$(seq 1 5);do# Use seq to generate the numbersfile_name="$dir_name/file_$i.txt"touch"$file_name"if[!-f"$file_name"];then
echo"Error: Failed to create file '$file_name'."fi
done
Hi π, I'm Harshit, a Full-Stack developer, I enjoy making content around Tech, Programming/coding, I share everything I learn or find interesting (20k+ reads)
Don't forget to connect with me on X!
Hi @rajeshroyal,
Thanks for your feedback! I appreciate the suggestion. The approach I used {1..5} does create five separate files in Bash, since it expands before execution, generating unique filenames (file_1.txt, file_2.txt, etc.).
I see why you might be getting file_{1..5}.txt , this can happen if the script is run in sh instead of bash, as sh doesnβt support {1..5} expansion. Your (seq 1 5) approach is a great alternative for broader shell compatibility, though {1..5} is slightly more efficient in pure Bash.
Really appreciate the discussion, always great to learn different approaches! π
Hi π, I'm Harshit, a Full-Stack developer, I enjoy making content around Tech, Programming/coding, I share everything I learn or find interesting (20k+ reads)
Don't forget to connect with me on X!
Hi π, I'm Harshit, a Full-Stack developer, I enjoy making content around Tech, Programming/coding, I share everything I learn or find interesting (20k+ reads)
Don't forget to connect with me on X!
@harshit_rwt there is an error in the
firstscript.shfile, It will not create 5 files (at least for me) instead it will create only 1 file with the namefile_{1..5}.txt.The below code works fine:
Nice article and good reading.
Hi @rajeshroyal,
Thanks for your feedback! I appreciate the suggestion. The approach I used {1..5} does create five separate files in Bash, since it expands before execution, generating unique filenames (file_1.txt, file_2.txt, etc.).
I see why you might be getting file_{1..5}.txt , this can happen if the script is run in sh instead of bash, as sh doesnβt support {1..5} expansion. Your (seq 1 5) approach is a great alternative for broader shell compatibility, though {1..5} is slightly more efficient in pure Bash.
Really appreciate the discussion, always great to learn different approaches! π
Thanks @harshit_rwt
"This is what i am looking for π₯π₯"
Very informative
Informative, Thank you.
Nice
This is a great tutorial on bash script.
Thank you
Thankyou for such a positive feedback,
Glad you liked it!
Great tutorial on bash scripting. Thanks
Such a great article, so thorough and detailed. Thanks for this, Great π work indeed.
Thank you for your kind words! Really happy that you enjoyed it. Your appreciation means a lot! β¨
Because it's basics, I think you need to mention how to save and exit the vim after entering the content. Like :wq at the beginning.