Linked Questions

40
votes
1answer
106k 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 ...
4
votes
7answers
10k 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. #! /...
4
votes
4answers
3k 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]='...
2
votes
3answers
20k 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.
3
votes
2answers
6k 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 ...
3
votes
2answers
14k 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 ...
1
vote
1answer
8k 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 ...
0
votes
1answer
2k 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 ...
1
vote
1answer
3k 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" ...
3
votes
3answers
998 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 ...
1
vote
2answers
2k 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: ...
1
vote
1answer
1k 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?...
-2
votes
1answer
2k 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 ...
0
votes
3answers
887 views

Bash Script, find file size and compare not running [duplicate]

Very new to bash as you will see in code below. I want to get the file size in bytes of a file, compare that to a fixed value and send an email if the latter is too small. Code: #!/bin/bash f=$(...
0
votes
1answer
481 views

Bash script -ne comparison giving “command not found” error [duplicate]

In my bash script I wish to ssh into a machine, and if the machine is down, perform something within an if statement. To check whether or not the the machine is down I have an if statement using the ...

15 30 50 per page