Discussion:
почему не работает shell скрипт?
(слишком старое сообщение для ответа)
Lev Zagatov
2020-11-26 17:25:25 UTC
Permalink
Здpавствуйте, написал shell-скpипт. Он не pаботает.
Что может не нpавиться dash?

========
#!/bin/sh
# cls -- simple shell-script to clear screen with back-clear
# author: Lev Zagatov; requires: ncurses, coreutils;

if [ "$1" == 'back' ]; then
if [ "$2" ]; then
CountOfLines=$2;
else
CountOfLines=$(tput lines || stty size | sed 's/ [0-9]*$//g');
fi;

for i in $(seq 1 $CountOfLines); do
echo;
done;
else
if [ $(command -v clear) ]; then
clear;
elif [ ! $(command -v clear) && $(command -v tput) ]; then
tput clear;
else
echo 'WARNING: It seems like there is no `clear` or `tput` installed.';
echo 'Do you want to do back-clear instead? (Ret -- yes, Ctrl-c -- no)';
read a;
for i in $(seq 1 $(stty size | sed 's/ [0-9]*$//g')); do
echo;
done;
fi;
fi;
========

Выхлоп:

========
/usr/local/bin/cls: 5: [: unexpected operator
========

С благодаpностью, Лев Загатов
Sergey Anohin
2020-11-27 07:55:41 UTC
Permalink
Hello, Lev!

LZ> Здpавствуйте, написал shell-скpипт. Он не pаботает.
LZ> Что может не нpавиться dash?
LZ> ========
LZ> #!/bin/sh
LZ> # cls -- simple shell-script to clear screen with back-clear
LZ> # author: Lev Zagatov; requires: ncurses, coreutils;
LZ> if [ "$1" == 'back' ]; then
LZ> if [ "$2" ]; then
LZ> CountOfLines=$2;
LZ> else
LZ> CountOfLines=$(tput lines || stty size | sed 's/ [0-9]*$//g');
LZ> fi;
LZ> for i in $(seq 1 $CountOfLines); do
LZ> echo;
LZ> done;
LZ> else
LZ> if [ $(command -v clear) ]; then
LZ> clear;
LZ> elif [ ! $(command -v clear) && $(command -v tput) ]; then
LZ> tput clear;
LZ> else
LZ> echo 'WARNING: It seems like there is no `clear` or `tput` installed.';
LZ> echo 'Do you want to do back-clear instead? (Ret -- yes, Ctrl-c -- no)';
LZ> read a;
LZ> for i in $(seq 1 $(stty size | sed 's/ [0-9]*$//g')); do
LZ> echo;
LZ> done;
LZ> fi;
LZ> fi;
LZ> ========
LZ> Выхлоп:
LZ> ========
LZ> /usr/local/bin/cls: 5: [: unexpected operator
LZ> ========

В интернетах пишут:
There is no mistake in your bash script. But you are executing it with sh which
has a less extensive syntax ;)
So, run bash ./choose.sh instead :)

Ну или типа шебанг поменять?

С наилучшими пожеланиями, Sergey Anohin.
Zhenja Kaliuta
2020-11-27 08:55:29 UTC
Permalink
Hi, Sergey!

On Fri, 27 Nov 2020 10:55:41 +0200 Sergey Anohin writes:

LZ>> #!/bin/sh
LZ>> # cls -- simple shell-script to clear screen with back-clear
LZ>> # author: Lev Zagatov; requires: ncurses, coreutils;
LZ>> if [ "$1" == 'back' ]; then

[...]

LZ>> ========
LZ>> Выхлоп:
LZ>> ========
LZ>> /usr/local/bin/cls: 5: [: unexpected operator
LZ>> ========

SA> В интернетах пишут:
SA> There is no mistake in your bash script. But you are executing it with sh
SA> which has a less extensive syntax ;)
SA> So, run bash ./choose.sh instead :)

SA> Ну или типа шебанг поменять?

вместо замены одного == ? У вас нет других интернетов?
Loading...