Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Just some additional comments:
do not use cat filename | grep ...., but grep .... filename (cat and pipe is not required at all)
use an editor with syntax highlight and you will see immediately if something is wrong (at least in most cases)
use [code]here comes your script[/code] to keep formatting of your post
I put code and code and the beginning and end of the script and now getting:
myscript.sh: line 6: please select the log file you want: command not found
myscript.sh: line 6: please select the log file you want: command not found
myscript.sh: line 6: please select the log file you want: command not found
myscript.sh: line 6: please select the log file you want: command not found
myscript.sh: line 6: please select the log file you want: command not found
this is so confusing lol
I just want to have a menu system so I am able to view any logs I want to
You may have an extra line there, the absolute first line should be your bang line:
Code:
#!/bin/bash
Line #5 I have would be:
Code:
options=("system log" "boot log" "Quit")
And it appears that line #5 in your error situation is one above that:
Code:
PS3='Please select the log file to view: '
My only guesses there are:
You have an extra line before the #!/bin/bash line
You've added/edited beyond your original post, because the copied error has a lowercase 'p' for "Please" whereas your original posting has that as uppercase.
See below about posting your code with [CODE] tags.
Make sure the #!/bin/bash is your absolute first physical line of the script.
The complaint appears to be taking your "please select" text as a command, which means the shell parser is all out of alignment with your coded intentions.
The script worked when I cut/pasted it in the original form, with the added quotation I mentioned.
I put code and code and the beginning and end of the script and now getting:
myscript.sh: line 6: please select the log file you want: command not found
myscript.sh: line 6: please select the log file you want: command not found
myscript.sh: line 6: please select the log file you want: command not found
myscript.sh: line 6: please select the log file you want: command not found
myscript.sh: line 6: please select the log file you want: command not found
this is so confusing lol
I just want to have a menu system so I am able to view any logs I want to
any ideas? thanks again
No, no, no, no, no ...
The [code] framers are only used to post code to a post in this forum. As I've said, follow the link in my signature showing how to add those tags to your posts.
pan's comment was not for your script. See my last suggestion.
yes, you need to put set -xv at the very beginning of the script (second line) - just to see what's happening.
And you will see select makes a loop itself, your break will quit that loop, but not the while loop. Also you modified the script and I have no idea what was running.
THAAAAANNNKKKS GUYS I GOT IT WORKING! i just copied/pasted my original script. however when i select an option it shows the 3 options again? if you know what i mean? i would of thought if i selected boot log that it would write to the booterr.txt and just exit
THAAAAANNNKKKS GUYS I GOT IT WORKING! i just copied/pasted my original script. however when i select an option it shows the 3 options again? if you know what i mean? i would of thought if i selected boot log that it would write to the booterr.txt and just exit
That's because in options 1 or 2 you just break your switch statement and the loop continues. Only option #3 exits. If you wish to exit, then you can add exit to any or all cases.
I think you're getting the gist. Check my blogs, here's one with some of my takes on bash scripting, debugging it, and other suggestions, BASH Scripting for Dummies and Geniuses
Seems like you're experimenting with BASH scripts and this is one of your experiments. Good job. I say keep posting some further works and questions or if you're seeking comments, lots of people usually reply to script questions.
Not that some of the other common guru's, Moderators, or others aren't also very adept. Just the username danielbmartin in LQ comes up a lot. They play a lot with scripts, post them, and also post for script questions and such. They seem to be working just for their own intellect and technical entertainment (I believe they mentioned that in one post), but if you search for posts by them, you'll see a lot of scripts as well as variations that many others have offered. Or just search the forums in general for BASH SCRIPT, believe me, you'll find a ton of forum posts. Lots of times you can just cut/paste many of the scripts and try them out.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.