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: limited time
Subject: Re: Tilde expansion in awk pipes
Date: Sun, 6 Oct 2024 15:14:13 +0530

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

==========

Though just for reference I opened a pipe in lua to test whether it behaves the 
same as awk with the following :-

local handle1 = io.popen "echo ~''"
local output1 = handle1:read "a"
handle1:close()
local handle2 = io.popen "echo ~'/path/to/file'"
local output2 = handle2:read "a"
handle2:close()
local handle3 = io.popen "echo ~\"/path/to/file\""
local output3 = handle3:read "a"
handle3:close()
local handle4 = io.popen "echo $ZSH_VERSION"
local output4 = handle4:read "a"
handle4:close()

print(output1,output2,output3,"Zsh Version = "..output4)

And it produces a similar output

❯ lua script.lua
~
        ~/path/to/file
        ~/path/to/file
        Zsh Version = 5.9

==========

So it seems this situation is definitely not unique to awks (other versions of 
awk including mawk behave similarly) or zsh since bash gives the same output as 
well, but not sure whether to call this a bug or not. Nevertheless, I’m 
including this here for reference.

reply via email to

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