Hello Malcolm Fitzgerald.  Thanks for your feedback about fish and its
documentation.  It looks like, if I am understanding correctly, your issue was
that you were putting parentheses around the condition of an if statement.  This
is not a part of the syntax of an if statement in fish, and it is not a part of
the syntax of an if statement in any other shells except the C shells (csh/tcsh)
[1].

In fish, parentheses represent command substitution [2], which is why the error
messages you were getting mention command substitution.

The Fish tutorial is full of examples of if that do not use parentheses.  The
man page for if [3] also shows the syntax and examples, with no parentheses.

Still, it might be a good idea to add an explicit warning to the documentation
not to put parentheses around the condition of an if statement lest you get an
error.

Also, I will give some unsolicited advice since you wrote that you are new to
shell programming.  I would not give a fish shell script the extension ".sh".  I
would reserve that extension for scripts that are compatible with /bin/sh.  My
fish shell scripts have an extension of ".fish", or no extension, and all start
with "#!/usr/bin/fish".

[1] https://hyperpolyglot.org/unix-shells#execution-control
[2] https://hyperpolyglot.org/unix-shells#quoting
[3] http://fishshell.com/docs/current/cmds/if.html


On Mon, May 3, 2021, at 00:20, Malcolm Fitzgerald wrote:
> Why doesn't the section "Command Substitution" in the otherwise 
> excellent documentation say, "you are only allowed to use command 
> substitution in X and Y" or perhaps "you are not allowed to use command 
> substitution in  Z", or simply, "Don't wrap test statements in round 
> brackets." This addendum would/could/might help someone like me in the 
> future.
> 
> TLDR; version:
> 
> I have been bumping my head against a wall trying to discover why I was 
> seeing this error message.
> 
> $ ./ProcessSetDeals.sh
> Failed to execute process './ProcessSetDeals.sh'. Reason:
> exec: Operation not permitted
> 
> At first I thought it was a user permission problem, so I used sudo
> 
> $ sudo ./ProcessSetDeals.sh
> Password:
> sudo: unable to execute ./ProcessSetDeals.sh: Operation not permitted
> 
> That didn't help. I'm kinda new to shell scripting, so I don't have a 
> lot of experience to fall back on. After too many rounds of doing the 
> same things in slightly different ways I tried this.
> 
> $ /usr/local/bin/fish ./ProcessSetDeals.sh
> ./ProcessSetDeals.sh: Command substitutions not allowed
> <W> fish: Error while reading file ./ProcessSetDeals.sh
> 
> I really hadn't expected to get an easter egg. If only I knew what to do 
> with it.
> 
> Unfortunately I had used command substitution everywhere. It wasn't 
> until I'd removed all the functions and all the control structures that 
> I could get my script to run. That made me desperate enough to read the 
> documentation (again!) and while I was doing that I found the address 
> for this mailing list. Not exactly hidden but I don't imagine it's a 
> high volume list.
> 
> Then, to figure out what help to ask for, I was testing the lines that 
> used command substitution and I discovered this:
> 
> $ if ( test $status = 0 
> )                                                                             
>                                                                               
>                                                             � 
> �
> fish: Command substitutions not allowed
> if ( test $status = 0 )
>    ^
> 
> Wow. In hindsight that was easy and I've learnt a lot of fishy things 
> from the documentation too, so there are upsides to the learning process.
> 
> thanks for the great shell,
> 
> Malcolm
> 
> 
> 
> 
> 
> 
> 
> 
> 
> _______________________________________________
> Fish-users mailing list
> Fish-users@lists.sourceforge.net <mailto:Fish-users%40lists.sourceforge.net>
> https://lists.sourceforge.net/lists/listinfo/fish-users
> 


_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to