Welcome to the new Linux Foundation Forum!
Bash scripting assistance needed please.
Hey there Guys / Girls,
I am busy doing 100 different things and configurations on one of my systems and as such I have had places where folders and paths were not existing / missing.
So I wrote this little guy to let me know.
FOLDERS="/u01/stuffs/data
/u01/stuffs/music
/u01/stuffs/information"
for f in $FOLDERS
do
echo "$f"
if [[ -d "${f}" [[ ; then
echo "WOHOO its there"
echo ""
fi
echo "Bummer no path like that."
echo ""
done
/u01/stuffs/music
/u01/stuffs/information"
for f in $FOLDERS
do
echo "$f"
if [[ -d "${f}" [[ ; then
echo "WOHOO its there"
echo ""
fi
echo "Bummer no path like that."
echo ""
done
Now I am adding it to a little bash applet where it will load various things. one being this script. BUT heres the issue.
How can i get the FOLDERS variable to read from a file.
so for instance have a folders.txt with all the paths listed in it, then my variable Folders will just be a read of that entire file.
everywhere i can find something they are always read 1 line to 1 variable, and thats where im stuck, I would like to keep it 1 variable. somehow.......
Thanks for any assists.
0
Comments
folders.txt contents:
Suggestions:
1- Don't use capital names for variables. By convention that is used for environment variables
2- Do you really need to keep the folders in an array? Why if you already have the list in a file?
3- This won't deal with "newline" characters in folder names as it won't work with "does format" files either (lines don't end with a "newline" character)
About what mfillpot said:
- do *not* use cat for that!!! It's totally unnecessary and resource consuming: it's calling an external program (cat) and sending the output back to the main program. Even if it seems to work, you'd be surprised how many headaches you'll find in the future.
Regards
About what mfillpot said:
- do *not* use cat for that!!! It's totally unnecessary and resource consuming: it's calling an external program (cat) and sending the output back to the main program. Even if it seems to work, you'd be surprised how many headaches you'll find in the future.
Regards[/quote]
That is a great recommendation, this will help on larger files and files with troublesome characters.