BASH IF statements Part II
Me again, have a problem, again, need some help, again! :)
I have written this:
I basically want all the if statements to run, not just one or the other. How can I do this? I know it's probably a simple thing I'm missing and/ or doing wrong, but just need a nudge to the Great, Big, Wonderful Answer!
Any help please? :)
I don't know if I understand what it is you want to accomplish.
The above code, when edited to fix some 'errors', executes all the if-then parts and prints the appropriate response.
- added bash hashbang,
- after each elif there should be a then,
- removed done statement.
Hope this is what you wanted.
if [ $P1 == "#Text" ]
echo "Page1.html's text is commented out..."
if [ $P1 == "Text" ]
echo "Page1.html's text is NOT commented out..."
if [ $P2 == "#Text" ]
echo "Page2.html's text is commented out..."
if [ $P2 == "Text" ]
echo "Page2.html's text is NOT commented out..."
True but pointless, the if statements are mutually exclusive:
If $P1 is set to "Text" then it can't also be "#Text"
However, we don't know the format of /folder/file.conf, if the file contains more than 1 reference for the html files the results could be different than expected.
Also, the original script looks to be incomplete (unless the done statement was supposed to be a comment.
Thanks for the help so far :)
The "done" I put in due to pure desperation since what I was trying simply wasn't working.
There are more than one instance of both "Text" and "#Text" in the file.conf, but the values Page1.html, Page2.html, Page3.html and Page4.html are all unique.
Basically I want this portion of script to run first, then a second portion allowing you to choose which page (page1.html or page2.html etc.) you want to have commented out. My second portion of script works pretty good, but the one problem I have is that if there is nothing to comment out my script will leave the entry in file.conf as it is (for example "Text...") which is fine. When the sample is already "#Text", it will add another (for instance "##Text").
This is basically to allow me to see which are commented out and which aren't so that the second portion of the script will be based on this portion's information.
So this script will feature in another long script, first showing you which entries are commented out and which aren't, then giving you an option of which entry you want to comment out/ enable, then perform your selected action, restart a service if you choose to, then exit.
Ah, OK! I see now I left out the "elif then" bit! Still learning I guess, thanks for everyone's help, you're all super! :) :)
|All times are GMT -5. The time now is 07:15 AM.|