CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Installation (https://www.cfd-online.com/Forums/openfoam-installation/)
-   -   [OpenFOAM.org] OpenFOAM 4.0, bad option -t in zsh (https://www.cfd-online.com/Forums/openfoam-installation/179465-openfoam-4-0-bad-option-t-zsh.html)

rdbisme October 31, 2016 06:16

OpenFOAM 4.0, bad option -t in zsh
 
Hello everybody,

I'm in the process of passing from OF 3.0.1 to OF 4.0. Meanwhile I also changed my shell from bash to zsh + OMZ since that is the shell I naturally use on my personal machines.

I'm experiencing a problem with the initial setup of the environment, in particular:

Code:

source OpenFOAM-4.0/etc/bashrc
returns an error:
Code:

OpenFOAM-4.0/etc/config.sh/aliases:73 bad option -t
I had no issues with OF3.0.1. In facts if we check the two different bashrc configuration scripts:

OpenFOAM 4.0

OpenFOAM 3.0.x

in the new version we have:

Code:

[ "$(type -t wmRefresh)" = "alias" ] && unalias wmRefresh || unset wmRefresh
The type builtin has different arguments in bash and in zsh

bash
Code:

type
 type [-afptP] [name …]

zsh
Code:

type [ -wfpamsS ] name ...

# Equivalent to whence -v

In particular no -t option is available. In zsh the most similar command to type -t would be, I guess, type -w (that prints a <name>: <type> string instead of just <type> as for bash's type command).
I'm not a shell ninja, but anyone among you knows a cross-platform solution to this bug?

Taataa November 1, 2016 08:02

Just replace the line that includes the -t option with this one:

[ "$(type wmRefresh | awk '{print $4}')" = "alias" ] && unalias wmRefresh || unset wmRefresh

I found the answer here.

rdbisme November 2, 2016 09:46

Quote:

Originally Posted by Taataa (Post 623683)
Just replace the line that includes the -t option with this one:

[ "$(type wmRefresh | awk '{print $4}')" = "alias" ] && unalias wmRefresh || unset wmRefresh

I found the answer here.

Thanks for your help. What I did was:

Code:

[[ "$(type wmRefresh)" =~ "alias" ]] && unalias wmRefresh || unset wmRefresh
that should be portable also with bash. Basically looking for the word "alias" in the output of type. In bash it should print something like 'wmRefresh aliased to' and it should validate correctly. Didn't check though.

arvindpj December 30, 2016 12:10

Working in zsh shell
 
Here is the update on this.

Replace this L73: in etc/configh.sh/aliases :
Code:

[ "$(type -t wmRefresh)" = "alias" ] && unalias wmRefresh || unset wmRefresh
with this:

Code:

# For backward-compatibility unalias wmRefresh if it is defined as an alias
if declare -f wmRefresh > /dev/null
then
    unset wmRefresh
else
    unalias wmRefresh 2> /dev/null
fi

Cheers
:)


All times are GMT -4. The time now is 23:33.