New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding variable containing current shell pid #1202

Closed
bstarynk opened this Issue Dec 24, 2013 · 14 comments

Comments

Projects
None yet
10 participants
@bstarynk
Copy link

bstarynk commented Dec 24, 2013

Hello all,

I am missing the $$ special variable to denote the current shell's pid (see http://hyperpolyglot.org/unix-shells giving a nice table ...); has it been discussed and rejected? What files should I look in to consider adding it?

@zanchey

This comment has been minimized.

Copy link
Member

zanchey commented Dec 24, 2013

You are looking for the %self process expansion - see http://fishshell.com/docs/current/index.html#expand-process .

@xfix

This comment has been minimized.

Copy link
Member

xfix commented Dec 24, 2013

Perhaps it could be possible to mention %self when user types $$ followed by non-letter.

@bstarynk

This comment has been minimized.

Copy link

bstarynk commented Jan 8, 2014

The point is that $$ is very common in most other shells. So I believe that it should be expanded like %self is. Using $$ lowers the fish learning effort.

@maxfl

This comment has been minimized.

Copy link
Contributor

maxfl commented Jan 8, 2014

One of the problems with %self is that it is not expanded in a string. You can not create file file.%self
I dislike $$, but it has an advantage of expanding in this case.

@cljacobs

This comment has been minimized.

Copy link

cljacobs commented Jan 17, 2014

You can create such a file using touch file.(echo %self). It's a lot more typing, and not as intuitive to people moving from other shells, but I disagree that $$ should be expandable to the shell's pid for the same reasons fish ignores convention for many of those other special-case variable expansions other shells have adopted.

I don't really use %self very much, and even less in scenarios where it would be difficult to implement without a construct like $$, but if it's something people do a lot and given that it's already been given a special recognized syntax in process expansion, perhaps a variable expansion a la $argv would suffice, e.g. $pid or $self? This would violate the law of orthogonality, but possibly satisfies the law of user focus much better than the current way of doing things.

@zanchey

This comment has been minimized.

Copy link
Member

zanchey commented Oct 8, 2015

The lack of expansion in a string is #1074.

@krader1961

This comment has been minimized.

Copy link
Contributor

krader1961 commented Mar 24, 2016

I'm in agreement with @cljacobs. I don't think we should introduce $$ but introducing $PID or $SELF can be justified despite introducing a second way to do the same thing. Note the all uppercase names to mirror other vars like $PWD and minimize clashes with existing uses of their lowercase forms.

@krader1961 krader1961 added enhancement and removed question labels Mar 24, 2016

@ridiculousfish

This comment has been minimized.

Copy link
Member

ridiculousfish commented Mar 24, 2016

It's also very easy for any user to just write set SELF %self at the top of the script and then they have it. This wouldn't work in bash since bash forks for subprocesses, but it works in fish.

@krader1961

This comment has been minimized.

Copy link
Contributor

krader1961 commented Mar 24, 2016

That set SELF %self works actually surprises me. As does touch %self but not touch x.%self.

@kgadek

This comment has been minimized.

Copy link

kgadek commented Jul 29, 2016

I would add that using $$ is very common to detect the shell type itself. I use this to do that: ps -cp $$ | awk 'NR==2{sub(/^-?/, "", $NF); print $NF}' and it works quite nicely across macOS, Linux and FreeBSD and various shells… except fish.

@krader1961 krader1961 modified the milestone: fish-tank Nov 17, 2016

@krader1961 krader1961 added the RFC label Nov 17, 2016

@krader1961 krader1961 added this to the fish-future milestone Jun 21, 2017

@krader1961 krader1961 removed the RFC label Jun 21, 2017

@krader1961

This comment has been minimized.

Copy link
Contributor

krader1961 commented Jun 21, 2017

I'm removing the "RFC" label. This should be implemented. I have no objections to using %some-string to match process names containing that string. But given the quirks of %self (e.g., touch x.%self doesn't work) we should allow access to this info via normal variable expansion.

@faho

This comment has been minimized.

Copy link
Member

faho commented Jun 21, 2017

But given the quirks of %self (e.g., touch x.%self doesn't work) we should allow access to this info via normal variable expansion.

Okay. What should the variable be called? Note that $ is currently not a valid variable name. It's also not in any way explanatory, so I'm leaning towards using a more descriptive name. Some suggestions:

  • $SELF
  • $PID
  • $FISH_PID
  • $SHELL_PID

I like the latter two the most since they best explain what the variable is.

@xfix

This comment has been minimized.

Copy link
Member

xfix commented Jun 21, 2017

I think the name should be lowercase, considering shell PID is not an exported variable (for consistency).

@mqudsi mqudsi closed this in 0866653 Mar 9, 2018

@faho faho changed the title adding $$ support (for current shell pid) in fish adding variable containing current shell pid Sep 30, 2018

@faho faho modified the milestones: fish-future, fish-3.0 Sep 30, 2018

@cben

This comment has been minimized.

Copy link
Contributor

cben commented Oct 25, 2018

For the historic record, the new vars got called $fish_pid (for %self) and $last_pid (replacing %last).

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