This question already has answers here:
How can I compare a string to multiple correct values in Bash?
(5 answers)
Why does non-equality check of one variable against many values always return true?
(3 answers)
Closed 1 year ago.
I am very new to shell scripting, and i have had this error. I am using a while loop that goes a bit like this:
while [ "$variable" =! "hello" -o "$variable" =! "hi" ]
do
echo "variable isn't hi or hello"
done
but shell then gives the error [: too many arguments
Related
This question already has answers here:
What do $? $0 $1 $2 mean in shell script? [duplicate]
(2 answers)
What does it mean when shell command starts with a dot?
(1 answer)
Why should there be spaces around '[' and ']' in Bash?
(5 answers)
Meaning of $? (dollar question mark) in shell scripts
(8 answers)
Closed 2 months ago.
In shell script in the middle there is one function as
#!/bin/ksh
var=$?
.......
FILE_NAME="/dir/user/work/file/abc.txt"
. ${FILE_NAME}
. ${HOME_PATH}/script/abc.sh
.....
func_start() {
JOB_ID=$1
FLAG=$2
NODES=$3
while [$i -le $NODES]
........ }
exit 0
What does it mean here in this script as var=$?, . ${file name} & function func_start() job_id=$1 flag=$2 nodes=$3? I am not much clear about this.
$? returns the exit value of the last executed command. echo $? prints that value on console. zero implies a successful execution while non-zero values are mapped to various reason for failure.
$1 $2 $3 : according to GNU
A positional parameter is a parameter denoted by one or more digits, other than the single digit 0. Positional parameters are assigned from the shell’s arguments when it is invoked, and may be reassigned using the set builtin command.
This question already has answers here:
Brace expansion with variable? [duplicate]
(6 answers)
Closed 8 months ago.
I have a script.sh
#!/bin/bash
for i in {1..$1}
do
echo $i
done
someone could explain me why if I try
./script.sh 10 my output is {1..10}?
expected
1
2
...
10
You're echoing the parameter that you're passing in instead of printing out the loop iteration. Try:
echo $i
This question already has answers here:
Command not found error in Bash variable assignment
(5 answers)
How do I set a variable to the output of a command in Bash?
(15 answers)
Closed 1 year ago.
Hey guys I am trying to teach myself shell scripting, but I am stuck in a error and I am just unsure how to fix it. I have created a simple while loop that should just give a output from 0-9. This is the error I receive
./loops.sh: line 10: 0: command not found
./loops.sh: line 11: [: -lt:unary operator expected
Here is my code
#while loop
x= 0
while [ $x -lt 10 ]
do
echo $x
x= 'expr $x + 1'
done
This question already has answers here:
echo "#!" fails -- "event not found"
(5 answers)
How to escape history expansion exclamation mark ! inside a double quoted string?
(4 answers)
Closed 2 years ago.
I have tried so many variations to echo the following string:
![](../images/a.png)
my attempts
b="a.pdf"
$ echo -n "![](../images/""${b%.*}.png")
-bash: ![]: event not found
$ echo -n "\![](../images/""${b%.*}.png"\)
\![](../images/a.png)
How to get:
![](../images/a.png)
This question already has answers here:
How do I compare two string variables in an 'if' statement in Bash? [duplicate]
(12 answers)
Closed 4 years ago.
I have the following script
#!/bin/bash
if [ $1=="1" ]
then
echo $1
fi
Whenever I run ./myscript.sh 0 it still prints "0". I am not sure why? It prints whatever I type in because the if executes. What would I need to change?
Add proper spaces, i.e. before and after == inside if condition
#!/bin/bash
if [ $1 == "1" ]
then
echo $1
fi