The problem. I am doing shell script that running from the desktop launcher, and it failed to execute in certain condition. To express the problem, I very simplify the problem code. The code is very simple:
uxterm -e bash -c 'echo 1 | sudoedit /etc/fstab'
It works good when I run it from the terminal emulator, but when I make it launch from the desktop environment, it fails. Launch from the desktop I mean launching from sway WM with this config
bindsym Mod4+F10 exec uxterm -e bash -c 'echo 1 | sudoedit /etc/fstab'
I also tried alacritty terminal emulator, and weston compositor.
When I use uxterm -e bash path/to/script
, it works good.
What is the difference between launching from the terminal and from the desktop, between -c option and launching script?
I expect smooth launch in any environment, and the most important, I need to know whats wrong here.
EDIT: To be clear, there is my actual script that works with the problem:
#!/bin/bash
ere-escape() { sed 's/[[^.$()|*+?{\]/\\&/g' ; } ; export -f ere-escape
bre-escape() { sed 's/[[*$\^.]/\\&/g' ; } ; export -f bre-escape
filelist()
{
source profile-dirs
for LAYER in "${PROFILE_LAYERS[@]}"
do
find "$PROFILE_DIR/home/$LAYER" -type f -printf '%P\0' 2> /dev/null
find "$PROFILE_DIR/root/$LAYER" -type f -printf '/%P\0' 2> /dev/null
done | (
if [ "$1" ]
then cd -- "$HOME" && xargs -0 -- grep --null -il -F -e "$1" -- 2> /dev/null
else cat
fi
) | LC_COLLATE=C sort -z
}
export -f filelist
export SEARCH="/tmp/$(uuidgen)" ; touch "$SEARCH"
filelist |
(
cd "$HOME" &&
fzf --header='[ Tab: Select | ^E: Edit | ^R: Search | Alt+u/U: Update | [Alt+]<^>: Preview ]' \
--read0 \
--layout=reverse-list \
--multi \
--info=inline \
--preview-window='33%' \
--preview '
grep -i --color=always -e "^" -e "$(bre-escape < "$SEARCH")" -- {}
' \
--bind 'focus:transform-preview-label(echo [ {} ])' \
--bind 'change:change-preview-window(33%)' \
--bind 'right:change-preview-window(75%)' \
--bind 'left:change-preview-window(33%)' \
--bind 'esc:clear-query+clear-selection+close' \
--bind 'tab:toggle+down+show-preview' \
--bind='ctrl-r:reload(
printf -- "%s\\n" {q} > "$SEARCH"
filelist {q}
)+transform-prompt(echo "&"{q}" > ")+clear-query' \
--bind='alt-u:execute(
clear -x
echo "Updating user profile..."
profile-update.sh
clear -x
profile-push.sh
read -n1 -p"Done. Press any key."
)' \
--bind='alt-U:execute(
clear -x
echo "Updating root profile..."
sudo profile-update.sh "root"
clear -x
profile-push.sh
read -n1 -p"Done. Press any key."
)' \
--bind='ctrl-e:execute(
if [[ {} == /* ]]
then sudoedit -- {+}
else $EDITOR -- {+}
fi
)+clear-selection' \
--bind 'enter:execute(
[[ "$PAGER" != less* ]] && exit
JUMP="$(ere-escape < "$SEARCH" | ere-escape | sed "s/[!@]/\\\\\\\\\\\\&/g")" # Less special char double escaping
if [ "$JUMP" ]
then JUMP="+/${JUMP,,*}"
else JUMP="+/^"
fi
if [[ {} == /* ]]
then
if [ -r {} ]
then SUDO_EDITOR="$EDITOR" LESSEDIT="%E %g" EDITOR="sudoedit" $PAGER --use-backslash "$JUMP" -- {+}
else sudoedit -- {+}
fi
else
$PAGER --use-backslash "$JUMP" -- {+}
fi
)+clear-selection'
)
rm -f "$SEARCH"
EDIT: More details discovered. Somehow, editor is not becoming a foreground process.
# Works good
PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND
1 131055 131054 131054 ? -1 Sl 1000 0:03 alacritty
131055 131075 131075 131075 pts/0 136428 Ss 1000 0:00 \_ /bin/bash
131075 136428 136428 131075 pts/0 136428 S+ 1000 0:00 \_ /bin/bash /home/user/.my/bin/profile-config.sh
136428 136432 136428 131075 pts/0 136428 Sl+ 1000 0:00 \_ fzf --header=[ Tab: Select | ^E: Edit | ^R: Search | Alt+u/U: Upda...
136432 136478 136428 131075 pts/0 136428 S+ 1000 0:00 \_ /bin/bash -c if [[ '/etc/pacman.conf' == /* ]] ...
136478 136479 136428 131075 pts/0 136428 S+ 0 0:00 \_ sudoedit -- /etc/pacman.conf
136479 136480 136480 136480 pts/1 136481 Ss 0 0:00 \_ sudoedit -- /etc/pacman.conf
136480 136481 136481 136480 pts/1 136481 Sl+ 1000 0:00 \_ nvim -p /var/tmp/pacmanJYcL0eJF.conf
136481 136484 136484 136484 ? -1 Ssl 1000 0:00 \_ nvim --embed -p /var/tmp/pacmanJYcL0eJF.conf
# Not working:
PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND
1 136493 136492 136492 ? -1 S 1000 0:00 /bin/bash /home/user/.config/sway/hotkeys.sh profile_config
136493 136495 136492 136492 ? -1 Sl 1000 0:00 \_ alacritty -e /bin/bash -c ttitle.sh "${1##*/}" ...
136495 136516 136516 136516 pts/2 136516 Ss+ 1000 0:00 \_ /bin/bash -c ttitle.sh "${1##*/}" ...
136516 136521 136516 136516 pts/2 136516 S+ 1000 0:00 \_ /bin/bash profile-config.sh
136521 136528 136516 136516 pts/2 136516 S+ 1000 0:00 \_ /bin/bash profile-config.sh
136528 136575 136516 136516 pts/2 136516 S+ 0 0:00 \_ sudoedit -- /etc/pacman.conf
136575 136580 136580 136580 pts/3 136580 Ss+ 0 0:00 \_ sudoedit -- /etc/pacman.conf
136580 136581 136581 136580 pts/3 136580 Sl 1000 0:00 \_ nvim -p /var/tmp/pacmanvJESy88R.conf
136581 136584 136584 136584 ? -1 Ssl 1000 0:00 \_ nvim --embed -p /var/tmp/pacmanvJESy88R.conf
You can see that sudoedit stays as foreground process (stat Ss+).