Linked Questions
50 questions linked to/from Brackets in if condition: why am I getting syntax errors without whitespace?
67
votes
1
answer
198k
views
Bash if statement [: missing `]' error [duplicate]
I am having trouble with bash. I am trying to put a command in an if statement and then compare it to a string.
This works perfectly.
echo $(ipcs | grep Shared | awk '{print $2}')
When I put it in ...
25
votes
3
answers
104k
views
OR operator in bash scripting [duplicate]
This code generates a error line 3: [: missing `]'. So why am I getting such error?
#!/bin/bash
read x
if [ $x == "Y" ] || [ $x == "y"]
then
echo "YES"
else
echo "NO"
fi
Thanks in advance.
7
votes
7
answers
25k
views
How to compare 2 strings in UNIX shell script? [duplicate]
I have a variable which stores a string, the output of a sed command.
I want to execute a set of commands only if this string value matches either of the 2 other strings.
I used the below code.
#! /...
12
votes
2
answers
85k
views
linux bash if statement inside for loop [duplicate]
I am attempting to iterate through 1-30, say hello #number for each except for number 10. This is what I have which is not working
for i in {1..30}; do if [i != 10]; then echo "hello $i"; fi; done
...
4
votes
4
answers
10k
views
String comparison failing in bash [duplicate]
I'm attempting to loop through an array of strings, and do something a little different with one of the values. The string comparison fails on every element.
arr[0]='red'
arr[1]='blue'
arr[2]='...
5
votes
2
answers
13k
views
missing `]' error in unix shell script [duplicate]
I am trying to run a small script which check for two variables to see if they are empty or not.
I am getting the correct output but if also shows me error for missing right parenthesis. I tried using ...
1
vote
1
answer
11k
views
Bash error: "[y command not found" [duplicate]
I am trying to get this script to function correctly but I get ./passmark.sh line 7: [y command not found.
Here is my script
#!/bin/bash
# A simple script to ask a user for a pass mark and then ...
-3
votes
1
answer
21k
views
assign string to variable with if else condition [duplicate]
I have written the code. to check the variable value if it GL then SQLGL should XDOAPPL, if AP then SQLAP should assign XDOAPPL variable. but it is giving me the error.
APPL=$1
x=AP
y=GL
echo "Value ...
5
votes
1
answer
4k
views
Command substitution in if statement [duplicate]
I'm trying to compare the result of a command substitution to a string, like this:
if [$(ping $1)=="ping: unknown host localhosts"]
then
echo "no";
else
echo "yes";
fi
What am I doing wrong here?
1
vote
1
answer
5k
views
Unix Shell : Array assignment not working [duplicate]
I am learning array by following code
source_array_list[0]="a"
source_array_list[1]="a"
source_array_list[2]="a"
source_array_list[3]="a"
source_array_list[4]="a"
source_array_list[5]="a"
...
4
votes
1
answer
3k
views
Comparing working directory with "string" [duplicate]
I'm trying to compare the current working directory's path with my home directory's path.
user@machine:~$ echo $PWD
/home/user
user@machine:~$ if ["$PWD" = "/home/user"]; then echo True; else echo ...
0
votes
1
answer
3k
views
if/then loop using `cat` [duplicate]
teams.txt:
Bills
Jets
Dolphin
Patriots
.
for team in `cat teams.txt`
do
if ["$team" == "Bills"]
then
echo "$team hired Rex Ryan as coach"
fi
echo "$team Nation"
done
I keep ...
0
votes
2
answers
3k
views
if statement calling functions and improper result [duplicate]
The shell script is expected to call only one function, but calling both. How to fix this, the output is
both are same
both are not same
#!/bin/bash
var1=ORCL
var2=ORCL
function f1
{
...
1
vote
2
answers
3k
views
bash question about if and then [duplicate]
I'm writing this in my script. It has other parts but I'm getting stuck on this part only.
if [[$# == $year $month $day ]] ; then
cal $day $month $year
fi
When I run this it give me this msg:
[...
3
votes
3
answers
2k
views
Why is my script calling multiple functions? [duplicate]
I have a few sets of scripts that I've written to make setting up linux very simple. So I have made those scripts into separate functions instead and put it all in one script. I have numbers set so ...