Skip to main content
Add a lot more context
Source Link
Jacktose
  • 532
  • 6
  • 13

Edit: More context

I'm using Oh My Posh and Atuin with bash-preexec, all of which do something at prompt time. My example actually looks like this: Screenshot of example showing fancy prompt

They're set up in .bashrc like so:

eval "$(oh-my-posh init bash --config "${omp_config}")" # Get bash history number: set_poshcontext () { export _myhistcmd=$(( $(fc -l -1 | cut -f1) +1 )); } # Note the `+1`! ^^ [ -r "${HOMEBREW_PREFIX}/etc/profile.d/bash-preexec.sh" ] && . "${HOMEBREW_PREFIX}/etc/profile.d/bash-preexec.sh" eval "$(atuin init bash --disable-up-arrow)" 

To @Stéphane Chazelas questions:

$ typeset -p PS{1..4} declare -- PS1="\$(_omp_get_primary)" declare -- PS2="\$(_omp_get_secondary)" -bash: typeset: PS3: not found declare -- PS4="+ " $ echo "$PROMPT_COMMAND" __bp_precmd_invoke_cmd _omp_hook __bp_interactive_mode $ trap trap -- '__bp_preexec_invoke_exec "$_"' DEBUG 

Edit: More context

I'm using Oh My Posh and Atuin with bash-preexec, all of which do something at prompt time. My example actually looks like this: Screenshot of example showing fancy prompt

They're set up in .bashrc like so:

eval "$(oh-my-posh init bash --config "${omp_config}")" # Get bash history number: set_poshcontext () { export _myhistcmd=$(( $(fc -l -1 | cut -f1) +1 )); } # Note the `+1`! ^^ [ -r "${HOMEBREW_PREFIX}/etc/profile.d/bash-preexec.sh" ] && . "${HOMEBREW_PREFIX}/etc/profile.d/bash-preexec.sh" eval "$(atuin init bash --disable-up-arrow)" 

To @Stéphane Chazelas questions:

$ typeset -p PS{1..4} declare -- PS1="\$(_omp_get_primary)" declare -- PS2="\$(_omp_get_secondary)" -bash: typeset: PS3: not found declare -- PS4="+ " $ echo "$PROMPT_COMMAND" __bp_precmd_invoke_cmd _omp_hook __bp_interactive_mode $ trap trap -- '__bp_preexec_invoke_exec "$_"' DEBUG 
add context
Source Link
Jacktose
  • 532
  • 6
  • 13

I'm trying to break a long command substitution on to multiple lines, as discussed in this answer.

In a plain command pipeline, both explicit (\) and implicit line continuation work fine:

$ echo 'blah foo bar' \ > | grep -F 'blah' blah foo bar $ echo 'blah foo bar' | > grep -F 'blah' blah foo bar 

Inside of a command substitution, they both fail, and slightly differently:

$ foo=$(echo 'blah foo bar' \ > | grep -F 'blah') -bash: 4131 | grep -F 'blah') +1 : syntax error: invalid arithmetic operator (error token is "'blah') +1 ") $ foo=$(echo 'blah foo bar' | > grep -F 'blah') -bash: 4133 grep -F 'blah') +1 : syntax error in expression (error token is "grep -F 'blah') +1 ") 

MyI'm on bash 5.2.21 and .37. I'm testing at the command prompt, but my real use case is this in .bashrc:

SSH_AUTH_SOCK="$(\ls -l /tmp/ssh-*/agent.* 2> /dev/null | grep -F "$USER" | head -1 | awk '{print $NF}')" 

What's happening? Where did the +1 come from?
And is there a way to do this correctly? (I'm interested in portable solutions or bash-specific.)

I'm trying to break a long command substitution on to multiple lines, as discussed in this answer.

In a plain command pipeline, both explicit (\) and implicit line continuation work fine:

$ echo 'blah foo bar' \ > | grep -F 'blah' blah foo bar $ echo 'blah foo bar' | > grep -F 'blah' blah foo bar 

Inside of a command substitution, they both fail, and slightly differently:

$ foo=$(echo 'blah foo bar' \ > | grep -F 'blah') -bash: 4131 | grep -F 'blah') +1 : syntax error: invalid arithmetic operator (error token is "'blah') +1 ") $ foo=$(echo 'blah foo bar' | > grep -F 'blah') -bash: 4133 grep -F 'blah') +1 : syntax error in expression (error token is "grep -F 'blah') +1 ") 

My real use case is:

SSH_AUTH_SOCK="$(\ls -l /tmp/ssh-*/agent.* 2> /dev/null | grep -F "$USER" | head -1 | awk '{print $NF}')" 

What's happening? Where did the +1 come from?
And is there a way to do this correctly? (I'm interested in portable solutions or bash-specific.)

I'm trying to break a long command substitution on to multiple lines, as discussed in this answer.

In a plain command pipeline, both explicit (\) and implicit line continuation work fine:

$ echo 'blah foo bar' \ > | grep -F 'blah' blah foo bar $ echo 'blah foo bar' | > grep -F 'blah' blah foo bar 

Inside of a command substitution, they both fail, and slightly differently:

$ foo=$(echo 'blah foo bar' \ > | grep -F 'blah') -bash: 4131 | grep -F 'blah') +1 : syntax error: invalid arithmetic operator (error token is "'blah') +1 ") $ foo=$(echo 'blah foo bar' | > grep -F 'blah') -bash: 4133 grep -F 'blah') +1 : syntax error in expression (error token is "grep -F 'blah') +1 ") 

I'm on bash 5.2.21 and .37. I'm testing at the command prompt, but my real use case is this in .bashrc:

SSH_AUTH_SOCK="$(\ls -l /tmp/ssh-*/agent.* 2> /dev/null | grep -F "$USER" | head -1 | awk '{print $NF}')" 

What's happening? Where did the +1 come from?
And is there a way to do this correctly? (I'm interested in portable solutions or bash-specific.)

Source Link
Jacktose
  • 532
  • 6
  • 13

Multiline command substitution - syntax errors with mysterious `+1`

I'm trying to break a long command substitution on to multiple lines, as discussed in this answer.

In a plain command pipeline, both explicit (\) and implicit line continuation work fine:

$ echo 'blah foo bar' \ > | grep -F 'blah' blah foo bar $ echo 'blah foo bar' | > grep -F 'blah' blah foo bar 

Inside of a command substitution, they both fail, and slightly differently:

$ foo=$(echo 'blah foo bar' \ > | grep -F 'blah') -bash: 4131 | grep -F 'blah') +1 : syntax error: invalid arithmetic operator (error token is "'blah') +1 ") $ foo=$(echo 'blah foo bar' | > grep -F 'blah') -bash: 4133 grep -F 'blah') +1 : syntax error in expression (error token is "grep -F 'blah') +1 ") 

My real use case is:

SSH_AUTH_SOCK="$(\ls -l /tmp/ssh-*/agent.* 2> /dev/null | grep -F "$USER" | head -1 | awk '{print $NF}')" 

What's happening? Where did the +1 come from?
And is there a way to do this correctly? (I'm interested in portable solutions or bash-specific.)