Ошибка сценария оболочки ТОЛЬКО при использовании команды наблюдения

Вот моя текущая строка состояния:

status bar screenshot sound on

Когда звук отключен:

status bar screenshot sound off

Содержание status.sh, которое ~/.config/sway/configвызывает:

# The Sway configuration file in ~/.config/sway/config calls this script.
# You should see changes to the status bar after saving this script.
# If not, do "killall swaybar" and $mod+Shift+c to reload the configuration.

# The abbreviated weekday (e.g., "Sat"), followed by the ISO-formatted date
# like 2018-10-06 and the time (e.g., 14:01). Check `man date` on how to format
# time and date.
date_formatted=$(date "+%a %F %H:%M")

# "upower --enumerate | grep 'BAT'" gets the battery name (e.g.,
# "/org/freedesktop/UPower/devices/battery_BAT0") from all power devices.
# "upower --show-info" prints battery information from which we get
# the state (such as "charging" or "fully-charged") and the battery's
# charge percentage. With awk, we cut away the column containing
# identifiers. i3 and sway convert the newline between battery state and
# the charge percentage automatically to a space, producing a result like
# "charging 59%" or "fully-charged 100%".
battery_info=$(upower --show-info $(upower --enumerate |\
grep 'BAT') |\
egrep "state|percentage" |\
awk '{print $2}')

# "amixer -M" gets the mapped volume for evaluating the percentage which
# is more natural to the human ear according to "man amixer".
# Column number 4 contains the current volume percentage in brackets, e.g.,
# "[36%]". Column number 6 is "[off]" or "[on]" depending on whether sound
# is muted or not.
# "tr -d []" removes brackets around the volume.
# Adapted from https://bbs.archlinux.org/viewtopic.php?id=89648
audio_volume=$(amixer -M get Master |\
awk '/Mono.+/ {print $6=="[off]" ?\
$4" ": \
$4" "}' |\
tr -d [])

# Additional emojis and characters for the status bar:
# Electricity: ⚡ ↯ ⭍ 
# Audio:      
# Separators: \| ❘ ❙ ❚
# Misc:     ⭐  ↑ ↓ ✉ ✅ ❎
echo $audio_volume $battery_info  $date_formatted

Вот часть строки состояния~/.config/sway/config:

bar {
    position top

    # Keep in mind that the current directory of this config file is $HOME
    status_command while ~/.config/sway/status.sh; do sleep 1; done

    # https://i3wm.org/docs/userguide.html#_colors
    colors {
        # Text color of status bar
        statusline #f8b500

        # Background color of status bar
        background #5e227f
    }
}

status.shтакже работает с i3 при вызове из /.config/i3/configс использованием того же блока bar, что показан выше.

Вот ссылка на мою текущую конфигурацию Sway, содержащую status.sh.

0
07.03.2021, 05:56
1 ответ

В вашем скрипте нет шебанга . Команда watch, скорее всего, выполняет ее с использованием /bin/sh, который не поддерживает конструкцию подстановки процесса <(command)1:

$ cat myscript
cat <(echo foo)

$ watch -n 2./myscript

==>

Every 2.0s:./myscript                                                                   t400s: Sun Mar  7 09:09:04 2021
./myscript: 1:./myscript: Syntax error: "(" unexpected

тогда как

$ cat myscript
#!/bin/bash
cat <(echo foo)

$ watch -n 2./myscript

==>

Every 2.0s:./myscript                                                                   t400s: Sun Mar  7 09:07:32 2021
foo

  1. точнее, он передает команду sh -c '... ', которая затем следует правилам, изложенным в Какой интерпретатор оболочки запускает сценарий без шебанга?
0
18.03.2021, 22:26

Теги

Похожие вопросы