I do this in a script:
read direc <<< $(basename `pwd`)
and I get:
Syntax error: redirection unexpected
in an ubuntu machine
/bin/bash --version
GNU bash, version 4.0.33(1)-release (x86_64-pc-linux-gnu)
while I do not get this error in another suse machine:
/bin/bash --version
GNU bash, version 3.2.39(1)-release (x86_64-suse-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.
Why the error?
John Kugelman
343k67 gold badges518 silver badges566 bronze badges
asked Mar 17, 2010 at 12:58
Open the wayOpen the way
25.4k49 gold badges141 silver badges196 bronze badges
1
Does your script reference /bin/bash
or /bin/sh
in its hash bang line? The default system shell in Ubuntu is dash, not bash, so if you have #!/bin/sh
then your script will be using a different shell than you expect. Dash does not have the <<<
redirection operator.
Make sure the shebang line is:
#!/bin/bash
or
#!/usr/bin/env bash
And run the script with:
$ ./script.sh
Do not run it with an explicit sh
as that will ignore the shebang:
$ sh ./script.sh # Don't do this!
answered Mar 17, 2010 at 13:05
John KugelmanJohn Kugelman
343k67 gold badges518 silver badges566 bronze badges
6
If you’re using the following to run your script:
sudo sh ./script.sh
Then you’ll want to use the following instead:
sudo bash ./script.sh
The reason for this is that Bash is not the default shell for Ubuntu. So, if you use «sh» then it will just use the default shell; which is actually Dash. This will happen regardless if you have #!/bin/bash
at the top of your script. As a result, you will need to explicitly specify to use bash
as shown above, and your script should run at expected.
Dash doesn’t support redirects the same as Bash.
answered Oct 17, 2018 at 22:27
Chris PietschmannChris Pietschmann
29.3k35 gold badges119 silver badges166 bronze badges
Docker:
I was getting this problem from my Dockerfile as I had:
RUN bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
However, according to this issue, it was solved:
The exec form makes it possible to avoid shell string munging, and
toRUN
commands using a base image that does not contain/bin/sh
.Note
To use a different shell, other than
/bin/sh
, use the exec form
passing in the desired shell. For example,RUN ["/bin/bash", "-c", "echo hello"]
Solution:
RUN ["/bin/bash", "-c", "bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)"]
Notice the quotes around each parameter.
Toby Speight
26.2k47 gold badges64 silver badges98 bronze badges
answered Jan 3, 2017 at 15:26
kemicofa ghostkemicofa ghost
15.9k6 gold badges82 silver badges128 bronze badges
2
You can get the output of that command and put it in a variable. then use heredoc
. for example:
nc -l -p 80 <<< "tested like a charm";
can be written like:
nc -l -p 80 <<EOF
tested like a charm
EOF
and like this (this is what you want):
text="tested like a charm"
nc -l -p 80 <<EOF
$text
EOF
Practical example in busybox
under docker
container:
kasra@ubuntu:~$ docker run --rm -it busybox
/ # nc -l -p 80 <<< "tested like a charm";
sh: syntax error: unexpected redirection
/ # nc -l -p 80 <<EOL
> tested like a charm
> EOL
^Cpunt! => socket listening, no errors. ^Cpunt! is result of CTRL+C signal.
/ # text="tested like a charm"
/ # nc -l -p 80 <<EOF
> $text
> EOF
^Cpunt!
answered Feb 2, 2018 at 16:19
1
do it the simpler way,
direc=$(basename `pwd`)
Or use the shell
$ direc=${PWD##*/}
answered Mar 17, 2010 at 13:08
ghostdog74ghostdog74
320k56 gold badges255 silver badges342 bronze badges
Another reason to the error may be if you are running a cron job that updates a subversion working copy and then has attempted to run a versioned script that was in a conflicted state after the update…
answered Jun 6, 2011 at 17:02
On my machine, if I run a script directly, the default is bash
.
If I run it with sudo
, the default is sh
.
That’s why I was hitting this problem when I used sudo
.
Milo
3,2979 gold badges28 silver badges43 bronze badges
answered Dec 12, 2017 at 19:12
In my case error is because i have put «>>» twice
mongodump --db=$DB_NAME --collection=$col --out=$BACKUP_LOCATION/$DB_NAME-$BACKUP_DATE >> >> $LOG_PATH
i just correct it as
mongodump --db=$DB_NAME --collection=$col --out=$BACKUP_LOCATION/$DB_NAME-$BACKUP_DATE >> $LOG_PATH
luk2302
53.2k23 gold badges96 silver badges136 bronze badges
answered May 11, 2017 at 13:17
Before running the script, you should check first line of the shell script for the interpreter.
Eg:
if scripts starts with /bin/bash , run the script using the below command
«bash script_name.sh»
if script starts with /bin/sh, run the script using the below command
«sh script_name.sh»
./sample.sh — This will detect the interpreter from the first line of the script and run.
Different Linux distributions having different shells as default.
answered Jan 23, 2018 at 10:42
SijeeshSijeesh
1772 silver badges9 bronze badges
3
I ran a deployment script to setup my server as root. Then I tried to run another script called test.sh which had the following lines in it:
# Logging
exec > >(tee -a /var/log/test_full.log)
exec 2> >(tee -a /var/log/test_error.log)
However when I try this I get the following error:
test.sh: 19: test.sh: Syntax error: redirection unexpected
What might be causing this issue do you think? I’ve not heard of this error before.
asked Nov 24, 2013 at 19:00
0
This answer solves your problem, assuming that your script snippet is complete.
In brief, you are running your script through dash
, not bash
. The solution is as simple as adding the necessary #!/bin/bash
What a system runs by default if the #!
is missing varies from system to system. On my system, I don’t get your error because a shell that understands your redirections is run by default. I’ve had to simulate the case where dash
would be the default shell to reproduce your error.
answered Nov 24, 2013 at 20:04
LouisLouis
144k28 gold badges270 silver badges314 bronze badges
3
Assuming you run your script with ./myscript
, make sure your scripts starts with
#!/bin/bash
and not #!/bin/sh
or anything else. The error suggests that another shell than Bash is used.
If your script indeed do, check that /bin/bash
is not a symbolic link and that it indeed is Bash with /bin/bash --version
.
answered Nov 24, 2013 at 20:04
damienfrancoisdamienfrancois
49.7k9 gold badges90 silver badges102 bronze badges
5
I run the following script but i’m getting syntax error : redirection unexpected
#!/bin/sh
# Bash strict mode, stop on any error
set -euo pipefail
# Ensure all required environment variables are present
test -n "$DATABRICKS_WORKSPACE_RESOURCE_ID"
test -n "$KEY_VAULT"
test -n "$SECRET_NAME"
test -n "$ARM_CLIENT_ID"
test -n "$ARM_CLIENT_SECRET"
test -n "$ARM_TENANT_ID"
# Login
az login --service-principal -u "$ARM_CLIENT_ID" -p "$ARM_CLIENT_SECRET" -t "$ARM_TENANT_ID"
# Get a token for the global Databricks application.
# The resource name is fixed and never changes.
token_response=$(az account get-access-token --resource 2ff814a6-3304-4ab8-85cb-cd0e6f879c1d)
token=$(jq .accessToken -r <<< "$token_response")
# Get a token for the Azure management API
token_response=$(az account get-access-token --resource https://management.core.windows.net/)
azToken=$(jq .accessToken -r <<< "$token_response")
# Generate a PAT token. Note the quota limit of 600 tokens.
api_response=$(curl -sf $DATABRICKS_ENDPOINT/api/2.0/token/create
-H "Authorization: Bearer $token"
-H "X-Databricks-Azure-SP-Management-Token:$azToken"
-H "X-Databricks-Azure-Workspace-Resource-Id:$DATABRICKS_WORKSPACE_RESOURCE_ID"
-d '{ "comment": "Terraform-generated token" }')
pat_token=$(jq .token_value -r <<< "$api_response")
az keyvault secret set --vault-name "$KEY_VAULT" -n "$SECRET_NAME" --value "$pat_token"
any idea how can I get it to work ?
asked Feb 27, 2020 at 0:26
0
Here strings like <<< "$token_response"
are not supported by POSIX /bin/sh
Either switch to a shell that supports them such as /bin/bash
, or modify your command to something like
pat_token=$(printf '%sn' "$api_response" | jq .token_value -r)
answered Feb 27, 2020 at 0:33
steeldriversteeldriver
75.3k11 gold badges104 silver badges144 bronze badges
1
I do this in a script:
read direc <<< $(basename `pwd`)
and I get:
Syntax error: redirection unexpected
in an ubuntu machine
/bin/bash --version
GNU bash, version 4.0.33(1)-release (x86_64-pc-linux-gnu)
while I do not get this error in another suse machine:
/bin/bash --version
GNU bash, version 3.2.39(1)-release (x86_64-suse-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.
Why the error?
Does your script reference /bin/bash
or /bin/sh
in its hash bang line? The default system shell in Ubuntu is dash (http://linux.die.net/man/1/dash), not bash (http://linux.die.net/man/1/bash), so if you have #!/bin/sh
then your script will be using a different shell than you expect. Dash does not have the <<<
redirection operator.
Make sure the shebang line is:
#!/bin/bash
or
#!/usr/bin/env bash
And run the script with:
$ ./script.sh
Do not run it with an explicit sh
as that will ignore the shebang:
$ sh ./script.sh # Don't do this!
If you’re using the following to run your script:
sudo sh ./script.sh
Then you’ll want to use the following instead:
sudo bash ./script.sh
The reason for this is that Bash is not the default shell for Ubuntu. So, if you use «sh» then it will just use the default shell; which is actually Dash. This will happen regardless if you have #!/bin/bash
at the top of your script. As a result, you will need to explicitly specify to use bash
as shown above, and your script should run at expected.
Dash doesn’t support redirects the same as Bash.
Docker:
I was getting this problem from my Dockerfile as I had:
RUN bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
However, according to this issue, it was solved:
The exec form makes it possible to avoid shell string munging, and
to RUN
commands using a base image that does not contain /bin/sh
.
Note
To use a different shell, other than /bin/sh
, use the exec form
passing in the desired shell. For example,
RUN ["/bin/bash", "-c", "echo hello"]
Solution:
RUN ["/bin/bash", "-c", "bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)"]
Notice the quotes around each parameter.
You can get the output of that command and put it in a variable. then use heredoc
. for example:
nc -l -p 80 <<< "tested like a charm";
can be written like:
nc -l -p 80 <<EOF
tested like a charm
EOF
and like this (this is what you want):
text="tested like a charm"
nc -l -p 80 <<EOF
$text
EOF
Practical example in busybox
under docker
container:
[email protected]:~$ docker run --rm -it busybox
/ # nc -l -p 80 <<< "tested like a charm";
sh: syntax error: unexpected redirection
/ # nc -l -p 80 <<EOL
> tested like a charm
> EOL
^Cpunt! => socket listening, no errors. ^Cpunt! is result of CTRL+C signal.
/ # text="tested like a charm"
/ # nc -l -p 80 <<EOF
> $text
> EOF
^Cpunt!
do it the simpler way,
direc=$(basename `pwd`)
Or use the shell
$ direc=${PWD##*/}
On my machine, if I run a script directly, the default is bash
.
If I run it with sudo
, the default is sh
.
That’s why I was hitting this problem when I used sudo
.
Another reason to the error may be if you are running a cron job that updates a subversion working copy and then has attempted to run a versioned script that was in a conflicted state after the update…
Before running the script, you should check first line of the shell script for the interpreter.
Eg:
if scripts starts with /bin/bash , run the script using the below command
«bash script_name.sh»
if script starts with /bin/sh, run the script using the below command
«sh script_name.sh»
./sample.sh — This will detect the interpreter from the first line of the script and run.
Different Linux distributions having different shells as default.
In my case error is because i have put «>>» twice
mongodump --db=$DB_NAME --collection=$col --out=$BACKUP_LOCATION/$DB_NAME-$BACKUP_DATE >> >> $LOG_PATH
i just correct it as
mongodump --db=$DB_NAME --collection=$col --out=$BACKUP_LOCATION/$DB_NAME-$BACKUP_DATE >> $LOG_PATH
Comments Section
For reference, the command works on cygwin as well ( /bin/bash —version GNU bash, version 3.2.49(23)-release (i686-pc-cygwin) Copyright (C) 2007 Free Software Foundation, Inc. )
Though we thank you for your answer, it would be better if it provided additional value on top of the other answers. In this case, your answer does not provide additional value, since another user already posted that solution. If a previous answer was helpful to you, you should vote it up instead of repeating the same information.
Don’t you think that I explained the solution here with an example?
Is there anything here that isn’t adequately covered in John Kugelman’s answer (/a/2462357) written 8 years ago?
…or
echo 'text' | nc
which is even shorter.
I have «#!/bin/bash» on top the sh file, but it still gives that error. It worked when used bash ./script.sh as @chris’s said.
@ibilgen Are you running it with
sh ./script.sh
? Don’t run scripts with an explicit shell. Just type the script name./script.sh
so it can use the interpreter declared in the shebang line.
This made it possible for me to get the here-string running inside a Dockerfile. That here-string was needed for saying «yes» (y) to an «overwrite question» (not important: it was for
ssh-keygen -q -t rsa <<< ""$'n'"y"
, see stackoverflow.com/a/43235320/11154841).
Should I change default shell
dash
tobash
?
@kittygirl I just changed from ‘/bin/sh’ to ‘/bin/bash’ and it worked!!
No, don’t change the default shell. This is a bug in the script / how the script is run. Don’t make global changes to fix a local problem.
Related Topics
ubuntu
bash
Mentions
John Kugelman
Toby Speight
Milo
Amir Hossein
Open The Way
Motin
Sijeesh
Mansur Ul Hasan
Chris Pietschmann
Kemicofa Ghost
Michael Mather
References
2462317/bash-syntax-error-redirection-unexpected
Модераторы: /dev/random, Модераторы разделов
-
gaux
- Сообщения: 185
- ОС: FreeBSD
bash перенаправление вывода не работает
Не пойму почему не работает. Пишу как и положено:
while read STRING
do
….
done< <( cat «$filename» )
Syntax error: redirection unexpected
Нашел еше вариант синтаксиса:
while read STRING
do
….
done <<< ( cat «$filename» )
Тоже самое: Syntax error: redirection unexpected
Такой вариант не подходит, потому что переменные должны сущестовать после цикла.
cat «$filename» | while read STRING
do
….
done
Может кто знает почему это не работает? До этого работало и писал точно так же. Только похоже версия bash была другой.
bash —version
GNU bash, version 3.2.39(1)-release (x86_64-pc-linux-gnu)
Copyright © 2007 Free Software Foundation, Inc.
-
Sleeping Daemon
- Сообщения: 1450
- Контактная информация:
Re: bash перенаправление вывода не работает
Сообщение
Sleeping Daemon » 27.08.2008 15:49
gaux писал(а): ↑
27.08.2008 15:26
Не пойму почему не работает. Пишу как и положено:
while read STRING
do
….
done< <( cat «$filename» )Syntax error: redirection unexpected
Нашел еше вариант синтаксиса:
while read STRING
do
….
done <<< ( cat «$filename» )Тоже самое: Syntax error: redirection unexpected
Такой вариант не подходит, потому что переменные должны сущестовать после цикла.
cat «$filename» | while read STRING
do
….
doneМожет кто знает почему это не работает? До этого работало и писал точно так же. Только похоже версия bash была другой.
bash —version
GNU bash, version 3.2.39(1)-release (x86_64-pc-linux-gnu)
Copyright © 2007 Free Software Foundation, Inc.
Может так: done < $filename»
-
gaux
- Сообщения: 185
- ОС: FreeBSD
Re: bash перенаправление вывода не работает
Сообщение
gaux » 27.08.2008 16:31
Пример написал краткий, расписывать не стал, алгоритм сложнее. Вывод команды потом перенаправляется в цикл и строки обрабатываются. Не хотел создавать временный файл на диске, а хотел воспользоваться каналами. Вот оно как раз и не работает.
-
Rootlexx
- Бывший модератор
- Сообщения: 4439
- Статус: GNU generation
- ОС: Debian GNU/Linux
Re: bash перенаправление вывода не работает
Сообщение
Rootlexx » 27.08.2008 16:37
gaux писал(а): ↑
27.08.2008 15:26
while read STRING
do
….
done< <( cat «$filename» )
Всё работает:
Код: Выделить всё
[rootlexx@localhost ~]$ while read line; do printf "%sn" "$line"; done < <(cat /etc/fstab)
# Entry for /dev/hda3 :
UUID=a53647fe-149f-11dd-9805-a33ae3977bbd / reiserfs notail,relatime,user_xattr,acl 1 1
# Entry for /dev/hda7 :
UUID=a761614e-149f-11dd-9d6e-3b801869113b /home reiserfs notail,relatime,user_xattr,acl 1 2
/dev/hdc /media/cdrom auto umask=0,users,iocharset=utf8,noauto,ro,exec 0 0
/dev/hdd /media/cdrom2 auto umask=0,users,iocharset=utf8,noauto,ro,exec 0 0
/dev/fd0 /media/floppy auto umask=0,users,iocharset=utf8,noauto,exec,flush 0 0
# Entry for /dev/hda1 :
UUID=24E09FC7E09F9D9C /mnt/win_c ntfs-3g defaults 0 0
# Entry for /dev/hda5 :
UUID=8ADC25A7DC258E8F /mnt/win_d ntfs-3g defaults 0 0
none /proc proc defaults 0 0
# Entry for /dev/hda6 :
UUID=a750f5a2-149f-11dd-9e06-4592dc05695d swap swap defaults 0 0
[rootlexx@localhost ~]$
-
gaux
- Сообщения: 185
- ОС: FreeBSD
Re: bash перенаправление вывода не работает
Сообщение
gaux » 27.08.2008 16:55
Заработался%) Выполняемым не сделал и пытался скормить sh, а не bash:D
Хотя странно:
$ ls -l /bin/sh
/bin/sh -> bash
sh указывает на bash.
Так пишу:
$ sh /home/andrey/ldif/test.sh
/home/andrey/ldif/test.sh: line 3: syntax error near unexpected token `<‘
/home/andrey/ldif/test.sh: line 3: `while read line; do printf «%sn» «$line»; done < <(cat /etc/fstab)’
Так пишу:
$ bash /home/andrey/ldif/test.sh
Работает. Но программа то по идее одна и та же вызывается O_O
$ whereis sh
sh: /bin/sh /usr/share/man/man1p/sh.1p.gz /usr/share/man/man1/sh.1.gz
-
gaux
- Сообщения: 185
- ОС: FreeBSD
Re: bash перенаправление вывода не работает
Сообщение
gaux » 28.08.2008 08:25
rm_ писал(а): ↑
27.08.2008 17:01
Но программа то по идее одна и та же вызывается
Баш смотрит, под каким именем вызывается, и ведёт себя по разному в зависимости от этого.
Забыл совсем, что некоторые программы так работают, но обычно — это жесткая ссылка, а не мягкая На bash первый раз такой серьезный скрипт пишу. До этого в основном web занимался в никсах.
The script was effective even with the syntax error, so it seems that this question really boils down to how to run a script.
Running as an Executable File
To run a script that is in the current directory without explicitly invoking the shell, you must preface its name with ./
. It must also be executable.
chmod u+x install-depot-multisystem.sh
./install-depot-multisystem.sh
That will only work if the script starts with a hashbang line specifying what shell is supposed to run it.
If you ran chmod 777
on the script, and that helped, then the reason it helped was almost certainly that it gave you, as the owner of the script, execute permissions on the script. You also gave yourself and all other users read and write permissions, as well as execute permission to all other users. This is unnecessary, potentially a serious security problem. chmod u+x
is just as good, and much safer.
Invoking the Shell
Alternatively you can run the script by explicitly invoking the shell, like you had tried initially:
sh install-depot-multisystem.sh
The script has a .sh
extension, so it should be runnable with sh
. But in case the script author named it badly, and it’s really a bash
script, you can try running with bash
(as geirha suggested):
bash install-depot-multisystem.sh
Running in the Current Shell
This is included for completeness only—unless you wrote the script and know this will work properly, or the instructions that accompany the script say to run it this way, you should use one of the previous two methods instead. Many scripts will only work right if they have their own shell in which to run (which is accomplished by either of the above two methods).
With that said, you can attempt to run the script in the current shell, with the current shell’s environment, with either of the following commands:
. install-depot-multisystem.sh
source install-depot-multisystem.sh
Running as root
If the script is installing a systemwide program or service, it might need to be run as root. Do not run a script (or anything) as root unless you know you need to do so.
To run it as root, put sudo
in front of the command that runs it. Any of these three commands will work (though the first still requires execute permissions):
sudo ./install-depot-multisystem.sh
sudo sh install-depot-multisystem.sh
sudo bash install-depot-multisystem.sh
Я делаю это в скрипте:
read direc <<< $(basename `pwd`)
и я получаю:
Syntax error: redirection unexpected
на машине ubuntu
/bin/bash --version
GNU bash, version 4.0.33(1)-release (x86_64-pc-linux-gnu)
пока я не получаю эту ошибку на другой машине suse:
/bin/bash --version
GNU bash, version 3.2.39(1)-release (x86_64-suse-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.
Почему ошибка?
9 ответы
Ссылка на ваш сценарий /bin/bash
or /bin/sh
в его строке хеш-взрыва? Системная оболочка по умолчанию в Ubuntu — тире, Не колотить, так что если у вас есть #!/bin/sh
тогда ваш сценарий будет использовать другую оболочку, чем вы ожидали. Dash не имеет <<<
оператор перенаправления.
ответ дан 17 мар ’10, в 13:03
Если для запуска сценария вы используете следующее:
sudo sh ./script.sh
Тогда вы захотите использовать вместо этого следующее:
sudo bash ./script.sh
Причина этого в том, что Bash не является оболочкой по умолчанию для Ubuntu. Итак, если вы используете «sh», то он просто будет использовать оболочку по умолчанию; что на самом деле является Dash. Это произойдет независимо от того, есть ли у вас #!/bin/bash
вверху вашего скрипта. В результате вам нужно будет явно указать использовать bash
как показано выше, и ваш скрипт должен работать в ожидаемом режиме.
Dash не поддерживает переадресацию так же, как Bash.
ответ дан 17 окт ’18, 23:10
Докер:
У меня возникла эта проблема из моего Dockerfile, как и у меня:
RUN bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
Тем не менее, в соответствии с Эта проблема, было решено:
Компания Exec форма позволяет избежать путаницы в строке оболочки и
RUN
команды, использующие базовое изображение, не содержащее/bin/sh
.Внимание
Чтобы использовать другую оболочку, кроме
/bin/sh
, использовать Exec форма переходящая в желаемую оболочку. Например,RUN ["/bin/bash", "-c", "echo hello"]
Решение:
RUN ["/bin/bash", "-c", "bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)"]
Обратите внимание на цитаты вокруг каждый Параметр.
Создан 02 фев.
Вы можете получить результат этой команды и поместить его в переменную. тогда используйте heredoc
. Например:
nc -l -p 80 <<< "tested like a charm";
можно записать так:
nc -l -p 80 <<EOF
tested like a charm
EOF
и вот так (это то, что вы хотите):
text="tested like a charm"
nc -l -p 80 <<EOF
$text
EOF
Практический пример в busybox
под docker
контейнер:
kasra@ubuntu:~$ docker run --rm -it busybox
/ # nc -l -p 80 <<< "tested like a charm";
sh: syntax error: unexpected redirection
/ # nc -l -p 80 <<EOL
> tested like a charm
> EOL
^Cpunt! => socket listening, no errors. ^Cpunt! is result of CTRL+C signal.
/ # text="tested like a charm"
/ # nc -l -p 80 <<EOF
> $text
> EOF
^Cpunt!
Создан 02 фев.
сделай это проще,
direc=$(basename `pwd`)
Или используйте оболочку
$ direc=${PWD##*/}
ответ дан 17 мар ’10, в 13:03
Другая причина ошибки может заключаться в том, что вы запускаете задание cron, которое обновляет рабочую копию Subversion, а затем пытаетесь запустить сценарий с поддержкой версий, который после обновления находился в конфликтном состоянии …
Создан 06 июн.
На моей машине, если я запускаю сценарий напрямую, по умолчанию используется bash
.
Если я запустил его с sudo
, по умолчанию sh
.
Вот почему я столкнулся с этой проблемой, когда использовал sudo
.
ответ дан 12 дек ’17, 20:12
В моем случае ошибка связана с тем, что я дважды поставил «>>»
mongodump --db=$DB_NAME --collection=$col --out=$BACKUP_LOCATION/$DB_NAME-$BACKUP_DATE >> >> $LOG_PATH
я просто исправляю это как
mongodump --db=$DB_NAME --collection=$col --out=$BACKUP_LOCATION/$DB_NAME-$BACKUP_DATE >> $LOG_PATH
ответ дан 11 мая ’17, 14:05
Перед запуском сценария вы должны проверить первую строку сценария оболочки для интерпретатора.
Например: если скрипты начинаются с / bin / bash, запустите скрипт, используя следующую команду «bash имя_сценария.sh»
если сценарий начинается с / bin / sh, запустите сценарий, используя следующую команду «sh имя_сценария.sh»
./sample.sh — обнаружит интерпретатор из первой строки скрипта и запустит его.
В разных дистрибутивах Linux по умолчанию используются разные оболочки.
Создан 23 янв.
Не тот ответ, который вы ищете? Просмотрите другие вопросы с метками
bash
ubuntu
or задайте свой вопрос.