Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
07-21-2023, 12:15 PM
|
#1
|
LQ Newbie
Registered: Jul 2023
Location: New England
Distribution: Mint
Posts: 5
Rep:
|
Bash rejects syntax I think should work
I already know what I want to do is subject to criticism about style. <g>.
However, this question is about the bash parser.
I have a trivial little function:
function MyEcho ()
{ set +x; echo $1; set $DASHX; return }
The parser says "syntax error: unexpected end of file"
But
function MyEcho ()
{
set +x
echo $1
set $DASHX
return
}
works fine,
and
if [ 1 == 1 ]
then
{ echo hello; echo world; return }
works fine.
So why is the first use of multiple statements within braces incorrect
while the second is OK?
|
|
|
07-21-2023, 12:18 PM
|
#2
|
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,756
|
Welcome.
If the closing brace is on the same line as the return, then there needs to be a semicolon to separate them:
Code:
function MyEcho () { set +x; echo $1; set $DASHX; return; }
|
|
1 members found this post helpful.
|
07-21-2023, 12:37 PM
|
#3
|
LQ Newbie
Registered: Jul 2023
Location: New England
Distribution: Mint
Posts: 5
Original Poster
Rep:
|
Thank you
Thank you, Turbocapitalist. It works, of course. I thought I tried that before posting, but I guess I didn't.
|
|
|
07-21-2023, 12:39 PM
|
#4
|
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,756
|
No problem. There's also shell check which will catch many things too. There is a web interface for it or you can install it locally from your distro's repository.
|
|
|
07-21-2023, 03:38 PM
|
#5
|
Member
Registered: Nov 2008
Location: US
Distribution: slackware
Posts: 884
|
Welcome to LQ
FWIW, programming may have been a better place for this, but you got a good answer anyway, so no harm done 
|
|
|
07-22-2023, 08:43 AM
|
#6
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,345
|
see man bash:
Quote:
A simple command is ... terminated by a control operator.
|
Code:
control operator
A token that performs a control function. It is one of the following symbols:
|| & && ; ;; ( ) | |& <newline>
Based on this you need to have one of these symbols between return and } .
|
|
1 members found this post helpful.
|
All times are GMT -5. The time now is 05:08 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|