help-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Tilde expansion in awk pipes


From: b3ak3r
Subject: Re: Tilde expansion in awk pipes
Date: Sun, 6 Oct 2024 09:06:02 -0600
User-agent: Mozilla Thunderbird

On 10/6/24 3:44 AM, limited time wrote:
The command is definitely running in zsh

For example, I can echo various variables set by the shell and they will work 
as expected.

BEGIN {
   "echo $ZSH_EXECUTION_STRING" | getline executionstring
   "echo $ZSH_EVAL_CONTEXT" | getline zshevalcontext
   "echo $ZSH_VERSION" | getline zshversion
   print "Execution String =" , executionstring
   print "Zsh Eval Context =", zshevalcontext
   print "Zsh Version =", zshversion
}

❯ gawk -f script.awk
Execution String = echo $ZSH_EXECUTION_STRING
Zsh Eval Context = cmdarg
Zsh Version = 5.9

==========

The manpage for sh in my machine says :-
      sh is a POSIX-compliant command interpreter (shell).It is implemented
      by re-execing as either bash(1), dash(1), or zsh(1) as determined by the
      symbolic link located at /private/var/select/sh.If
      /private/var/select/sh does not exist or does not point to a valid shell,
      sh will use one of the supported shells.


And the link is pointing correctly

❯ readlink /private/var/select/sh
/bin/zsh

<snip>

I tested with explicit bash refs (/bin/bash -x -c "echo ~..") and it appears the only inconsistency is the "echo ~'/fubar'" case and it's across all the usual AWKs (gawk, mawk, oawk, etc.):

--

# command line test:
$ gawk 'BEGIN{cmd="/bin/bash -x -c \"echo ~/fubar\"" ;cmd |getline str ;close(cmd) ;print str }'

+ echo /home/uesrname/fubar
/home/username/fubar

# awk script test:
$ cat foo.awk
BEGIN{cmd="/bin/bash -x -c \"echo ~/fubar\"" ;cmd |getline str ;close(cmd) ;print str}

$ gawk -f foo.awk

+ echo '~/fubar'
~/fubar

--

In script form the 'echo' argument string gets *fully quoted* so of course it doesn't expand.

-B




reply via email to

[Prev in Thread] Current Thread [Next in Thread]