Use of read -d option on Ubuntu Bash Shell - linux

im trying to use that option of read command in my script but i get only the error message 'read: -d ilegal option' when i execute it. This is the code
#!bin/bash
read -d "." -p "Write here: " var
var>$1
Im trying to type the same code on terminal and its ok there.
I've checked the version's shell and is bash. Thanks for help

Run your script explicitly with bash script.sh not sh script.sh. Also make sure you have bash: bash --version.

Related

Is there a package a need to install to use operators with Bash? [duplicate]

I want to run this script:
#!/bin/bash
echo <(true)
I run it as:
sh file.sh
And I get "Syntax error: "(" unexpected" . I found some similar situations but still can't solve this.
I'm a beginner at shell scripting , but as I understand:
the shebang I use is correct and chooses the bash shell , so the process substitution syntax should work
I try the same from the command line and it works. I checked with echo $0 and it gives me "bash" , so what's the difference from running the command in the command line and from a script that invokes the same shell?
Maybe it's something simple, but I couldn't find an explanation or solution.
You should run your script with bash, i.e. either bash ./script.sh or making use of the shebang by ./script.sh after setting it to executable. Only running it with sh ./script.sh do I get your error, as commented by Cyrus.
See also: role of shebang at unix.SE
Remove export POSIXLY_CORRECT=1 from your ~/.bashrc or ~/.profile (etc.) files.
The issue is that process substitution is an added bash feature that is not part of the posix standards.
sh file.sh
errorsh: 3: Syntax error: "(" unexpected
solution:
bash file.sh

syntax error when compare two files using shell script [duplicate]

I want to run this script:
#!/bin/bash
echo <(true)
I run it as:
sh file.sh
And I get "Syntax error: "(" unexpected" . I found some similar situations but still can't solve this.
I'm a beginner at shell scripting , but as I understand:
the shebang I use is correct and chooses the bash shell , so the process substitution syntax should work
I try the same from the command line and it works. I checked with echo $0 and it gives me "bash" , so what's the difference from running the command in the command line and from a script that invokes the same shell?
Maybe it's something simple, but I couldn't find an explanation or solution.
You should run your script with bash, i.e. either bash ./script.sh or making use of the shebang by ./script.sh after setting it to executable. Only running it with sh ./script.sh do I get your error, as commented by Cyrus.
See also: role of shebang at unix.SE
Remove export POSIXLY_CORRECT=1 from your ~/.bashrc or ~/.profile (etc.) files.
The issue is that process substitution is an added bash feature that is not part of the posix standards.
sh file.sh
errorsh: 3: Syntax error: "(" unexpected
solution:
bash file.sh

How to run shell script without typing bash (bash command error:mapfile not found)

I am using mapfile -t to obtain content of a text file and assign it to array.
In Jenkins it works fine where it will prompt steps and what command executed in console output .When I try to run in local console for example putty it prompts.
mapfile: not found [No such file or directory]
I know that mapfile is a bash command is and I am able to run the shell program after typing bash and executing the script.Is there anyway that I don't need to type bash in order to run the program ?I include #!/bin/bash -x on top of the script it still display the same error .The reason I don't want to type bash and execute the script is due to that it did not show what are the errors when the script dies.It did not display the error handling process that was in the script and it did not display output when it runs the command.
Please open a new file called script in a text editor. Type your program in:
#!/bin/bash -x
set -e
item=$1
if [ $item = '-database' ] then
mapfile -t DATA < $DATA_FILES
fi
save the file, execute chmod u+x and then
./script "-database"
to run it.
That's it.
However, that script will print nothing.

Getting "Unknown command" when using "lftp -e"

I'm working on a bash script to automate FTP sessions, so I can run the same commands on multiple servers automatically)
lftp -u username,password ip_address -e **FILE_WITH_COMMANDS**
So the problem is that I somehow can't use a file with -f because I get an error like this:
Unknown command `commands'.
Does anybody know how to get around this problem?
Thank you very much!
To execute commands loaded from a file, use the -f switch:
-f execute commands from the file and exit
The -e switch is for executing a command specified on the command-line:
-e execute the command
So when you use -e commands, the lftp interprets it as a request to run the commands command. And there's no commands command, hence the error.
See also https://lftp.yar.ru/lftp-man.html

Set bash script in Eclipse

I have a bash script .sh which needs to be executed as a Target Simulator in Eclipse. The problem is, if I run the script with sh run.sh command in terminal, it throws Bad Substitution error. But it works perfectly with bash run.sh. Apparently, Eclipse run it with sh command cause it gives the same error in console. But how can I make Eclipse to run the script with bash instead?
I'm on Ubuntu 13.10.
bash and sh aren't the same shell. There are many constructs valid in bash that are not understood by sh.
Have you provided a correct sheebang as the first line of your script?
#!/bin/bash
If so -- and if Eclipse insist on running script with sh, you still have the option of wrap your script in a heredoc and pass it to bash explicitly:
sh$ cat run.sh
bash << EOF
#
# Here is your bash script
#
EOF
This is mostly a hack until you find how to instruct Eclipse of using the right shell. I'm sure there is a way!

Resources