Skip to content

Solaris 11 compatibility#224

Open
agkozak wants to merge 1 commit into
rupa:masterfrom
agkozak:solaris-compatibility
Open

Solaris 11 compatibility#224
agkozak wants to merge 1 commit into
rupa:masterfrom
agkozak:solaris-compatibility

Conversation

@agkozak

@agkozak agkozak commented Dec 18, 2017

Copy link
Copy Markdown

z requires a version of awk that has the -v option. Solaris 11 uses by default an antiquated version of awk that does not have that option. Its nawk does have -v, however. I propose adding the function

awk() {
    case $(uname -a) in
       SunOS*) nawk "$@" ;;
       *) command awk "$@" ;;
    esac
}

It simply redirects calls on awk to nawk on Solaris and should have no effect on other systems. I have tested it with both bash and zsh.

@agkozak

agkozak commented Dec 18, 2017

Copy link
Copy Markdown
Author

An even better idea: only run uname once, when the script is sourced, and only define the awk() function on Solaris:

case $(uname -a) in
  SunOS*) awk() { nawk "$@"; } ;;
esac

@agkozak

agkozak commented Jan 23, 2018

Copy link
Copy Markdown
Author

fasd's method seems even better: pick an available version of awk that supports the -v option, assign it to $_Z_AWK, and use that instead of calling on awk.

@agkozak agkozak force-pushed the solaris-compatibility branch from 72bbf69 to 6843d28 Compare February 23, 2018 06:51
@agkozak agkozak changed the title Solaris 11 compatibility (uses nawk) Solaris 11 compatibility Jul 28, 2018
@agkozak

agkozak commented Jul 28, 2018

Copy link
Copy Markdown
Author

Solaris sed lacks the -i option, so the z -x command won't work. We have to use a temporary file.

@rupa

rupa commented Sep 11, 2018

Copy link
Copy Markdown
Owner

i kinda suck at github flow - could you squash these commits so I can get a better look at them?

@agkozak agkozak force-pushed the solaris-compatibility branch from 993746e to ebb29b9 Compare September 11, 2018 15:56
@agkozak

agkozak commented Sep 11, 2018

Copy link
Copy Markdown
Author

@rupa Done!

@dmd dmd left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This additional complexity seems iffy considering the userbase of Solaris 11.

@agkozak

agkozak commented Oct 25, 2019

Copy link
Copy Markdown
Author

I think it would be a shame to give up on POSIX compliance (sed -i isn't in the standard) and having the script work on a genuine Unix distribution (whose default awk might be old enough not to have awk -v -- but another version of awk, such as nawk, will have it). If there's a simpler solution, I'm all for it -- but my fixes do work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants