LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-02-2012, 02:06 PM   #1
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian Stretch
Posts: 1,063

Rep: Reputation: 83
Shell based menu of options


I have been testing the Fish shell for a few days, enjoying it so far to an extent. It has bugs and lacks features, but behaves pretty well in the command line, and I like it for scripts too, because the syntax is a lot simpler and cleaner.

Like I said, it lacks features. I like the 'select' command in other shells, it creates a nice menu of options. For example:

Code:
navigate ()  	{
	PS3="Where do you want to go today? "
	select TARGET in google microsoft yahoo quit
	do
		case $TARGET in
			google	)
				local url=http://www.google.com 
				break ;;
			microsoft	)
				local url=http://www.microsoft.com 
				break ;;
			yahoo	)
				local url=http://www.yahoo.com 
				break ;;
			quit)	exit;;
			*)	exit ;;
		esac
	done
	lynx $url
}
Fish has no such feature so I guess I will have to use some external program. What do you recommend? I suppose things like zenity or dialog would be overkill?
 
Old 01-02-2012, 04:25 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
One of the major benefits of open source is that you can modify it to suit your preference and send those modifications back upstream to possibly benefit other users, why not have a go at extending it ?
 
Old 01-02-2012, 04:34 PM   #3
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian Stretch
Posts: 1,063

Original Poster
Rep: Reputation: 83
Programming in shell, any shell, is hard enough for me. I am absolutely incapable of modifying the shell itself. I am in fact considering migrating 100% (scripting and command line use) to Fish because I find the other shells too complicated.
 
Old 01-02-2012, 04:44 PM   #4
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Programming in shell is basically an extension of working in a shell, automating common tasks etc. If you work in a shell long enough then your shell scripting skills will evolve.
 
Old 01-02-2012, 07:09 PM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,848

Rep: Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012
While I'm not familiar with fish syntax, the select command is really just a specialized while true loop. You're example function could be rewritten like this in bash, for example:

Code:
navigate (){

	echo "1) google" >&2
	echo "2) microsoft" >&2
	echo "3) yahoo" >&2
	echo "4) quit" >&2
	
	while true; do

		read -n 1 -p "Where do you want to go today (1-4)? " target

		case $TARGET in
			1)	local url=http://www.google.com 
				break ;;

			2)	local url=http://www.microsoft.com 
				break ;;

			3)	local url=http://www.yahoo.com 
				break ;;

			4)	exit ;;

			*)	echo "Where's that?" ;;
		esac
	done

	lynx "$url"
}
I'm sure the basic idea can be adapted to almost any shell.
 
1 members found this post helpful.
Old 01-02-2012, 08:31 PM   #6
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian Stretch
Posts: 1,063

Original Poster
Rep: Reputation: 83
Quote:
Originally Posted by kbp View Post
Programming in shell is basically an extension of working in a shell, automating common tasks etc. If you work in a shell long enough then your shell scripting skills will evolve.
Sure, I have years of experience in shell programming, but I always have to make and correct at least ten mistakes until a new script runs as expected, because there are so many quirks and gotchas in Bash/sh/ksh/tcsh syntax. I am sick of (not) memorizing those. I will therefore not even touch zsh with a ten-foot pole. I remember I tried it for a few days many years ago and I got tired of it because it was too complex.

If you ever feel like reading about it, the author of the Fish shell points out exactly how Fish tries to be simpler and cleaner:

http://lwn.net/Articles/136232/

I have ported (rewritten) some 20 or 30 of my most used scripts, and they definitely look a lot more readable now. Everyday use of the command line is better, too. I make fewer mistakes.

Last edited by lucmove; 01-02-2012 at 08:32 PM.
 
Old 01-02-2012, 08:35 PM   #7
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian Stretch
Posts: 1,063

Original Poster
Rep: Reputation: 83
Smile

Quote:
Originally Posted by David the H. View Post
While I'm not familiar with fish syntax, the select command is really just a specialized while true loop. You're example function could be rewritten like this in bash, for example:
(...)
That was a very helpful reply. Thank you!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Menu bashed shell script for users shell 0.o Linux - Server 6 02-14-2013 07:00 AM
LXer: Webian Shell: Prototype Web-Based Shell LXer Syndicated Linux News 0 07-05-2011 11:00 AM
Right-click menu options yogomix Red Hat 1 07-13-2010 07:20 AM
menu for some options kopper27 Linux - Newbie 6 04-07-2010 04:35 AM
Boot menu options carlindenver Linux - Newbie 1 10-23-2005 02:30 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration