Linked Questions

67 votes
1 answer
198k views

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 ...
cokedude's user avatar
  • 1,131
25 votes
3 answers
104k views

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.
Rajat Garg's user avatar
7 votes
7 answers
25k views

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. #! /...
Devjith's user avatar
  • 145
12 votes
2 answers
85k views

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 ...
Oscalation's user avatar
  • 1,199
4 votes
4 answers
10k views

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]='...
a coder's user avatar
  • 3,353
5 votes
2 answers
13k views

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 ...
JavaQuest's user avatar
  • 207
1 vote
1 answer
11k views

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 ...
Lyall Johnson's user avatar
-3 votes
1 answer
21k views

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 ...
Arun GoWdA's user avatar
5 votes
1 answer
4k views

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?
Philip Kirkbride's user avatar
1 vote
1 answer
5k views

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" ...
Aman's user avatar
  • 1,291
4 votes
1 answer
3k views

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 ...
PwS's user avatar
  • 41
0 votes
1 answer
3k views

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 ...
Gino's user avatar
  • 1
0 votes
2 answers
3k views

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 { ...
user2439245's user avatar
1 vote
2 answers
3k views

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: [...
Hajir Golmohammadi's user avatar
3 votes
3 answers
2k views

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 ...
munchschair's user avatar

15 30 50 per page