mcc,
@mcc@mastodon.social avatar

Linux question:

In bash, I can write:
(cd .. && ls)
and it will run "ls" in the parent directory, but after the command executes I will not have CD'd. The CD is confined in the subshell in the ().

If I try this same command in the alternate shell "fish", it prints the error "command substitutions not allowed here" and nothing is executed. Is there a fish equivalent of "run this single line of commands in a rubber-room subshell whose variables and pwd do not escape"?

mcc,
@mcc@mastodon.social avatar

I found this exact question answered in a FAQ titled "fish for bash users": https://fishshell.com/docs/current/fish_for_bash_users.html#subshells

But my interpretation of its FAQ answer is "if this is what you want, have you considered simply wanting something different?"

fabiosantoscode,
@fabiosantoscode@mastodon.social avatar

@mcc ugh, I thought I heard fish was good?

juandesant,
@juandesant@astrodon.social avatar

@mcc is not exactly the same, but could you not do $(fish -c "cd .. ; ls ") inside of fish?

juandesant,
@juandesant@astrodon.social avatar

@mcc just tested in iSH after installing fish with apk add fish:

localhost:~# fish -c "ls"  
juandesant.rss  
localhost:~# fish -c "echo $(fish -c ls)"  
juandesant.rss  
localhost:~# fish -c "$(fish -c ls)"  
fish: Unknown command: juandesant.rss  
fish:   
juandesant.rss  

juandesant.rss is the only file in that directory.

virtulis,
@virtulis@loud.computer avatar

@mcc Well (pushd ..; ls; popd) seems to work, but it's three commands technically.

Edit: it's most certainly not a rubber room either. Is it in bash?

mcc,
@mcc@mastodon.social avatar

@virtulis for me this gives the same error about command substitution. but even if it did not, it's not quite the same because it will have different aborting behavior. I guess… if the middle one fails, does popd execute unconditionally?

mcc,
@mcc@mastodon.social avatar

@virtulis I tried {ls} and it gave me something about "use begin; end;" . This isn't my shell/computer so I'm a little confused…

unlambda,
@unlambda@hachyderm.io avatar

@mcc well, they do also say "if you really need it, just invoke fish -c 'your code here'"

So they get that some people really do need it, but they don't provide any feature for it, just the usual "you can always invoke fish as a separate process"

mcc,
@mcc@mastodon.social avatar

@unlambda @henryk Yeah, I'm not super impressed with this because now I gotta fiddle with a whole level of escaping?

jferg,
@jferg@flyovercountry.social avatar

@mcc Per that doc, is

fish -c 'cd .. && ls'; ls

not what you're looking for? It's definitely more unwieldy, and I'm not sure about piping stuff between the first command and second.

mcc,
@mcc@mastodon.social avatar

@jferg Thanks, I see it but the problem is now I have to think about escaping. It's awkward enough I'd wind up doing it another way…

shironeko,
@shironeko@fedi.tesaguri.club avatar

@mcc is this for a script?

mcc,
@mcc@mastodon.social avatar

@shironeko just at the command line

shironeko,
@shironeko@fedi.tesaguri.club avatar

@mcc in that case I would just type "fish" do what I need and type "exit"

mcc,
@mcc@mastodon.social avatar

@shironeko so the actual line is something like

(cd .. && ../build.sh) && dotnet run

and the goal is to be able to invoke this one line that does various things in different places, but get sensible rollback behavior (IE not find ourselves in another directory) if something fails partway through.

I thnk I can still emulate it with something like

pushd .. && build.sh && dotnet run | popd

but it'll be awkward

rst,
@rst@mastodon.social avatar

@mcc Parentheses for subshells isn't just bash, it's at least as old as the original Unix v7 Bourne shell, and is required of /bin/sh by Posix. (It's reasonable to have a shell that deliberately deviates from the Posix spec, but, well... fish appears to be one of those.)

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • DreamBathrooms
  • ngwrru68w68
  • modclub
  • magazineikmin
  • thenastyranch
  • rosin
  • khanakhh
  • InstantRegret
  • Youngstown
  • slotface
  • Durango
  • kavyap
  • mdbf
  • GTA5RPClips
  • JUstTest
  • tacticalgear
  • normalnudes
  • tester
  • osvaldo12
  • everett
  • cubers
  • ethstaker
  • Leos
  • anitta
  • cisconetworking
  • megavids
  • provamag3
  • lostlight
  • All magazines