Linked Questions
201 questions linked to/from Why should there be spaces around '[' and ']' in Bash?
-1 votes
2 answers
5k views
"if[ 0 -lt 1] command not found" error in shell script [duplicate]
I got error message as if[ 0 -lt 1] command not found. I just started shell scripting. I don't know what's wrong in my code: if[ $# -lt 1 ] then echo "Give a number as a parameter. Try again." ...
2 votes
1 answer
4k views
How to escape hyphen(-) in shell script? [duplicate]
My bash script keeps failing because it gets confused at the hyphen: if [ ! -d "$openssl-1.0.1i"]; then ... How do I escape it correctly?
1 vote
2 answers
6k views
Bash if then else syntax [duplicate]
I'm trying to do test automation with a bash script using if then else statements but I'm running into a few errors. For one, when I try to execute it I'm doing something wrong with the variable ...
0 votes
2 answers
3k views
Syntax error Cygwin If Else condition [duplicate]
I am using Cygwin to run a script, I am getting syntax error when i use if else condition. Can you please tell me what is wrong with my script ? ./test.sh: line 10: syntax error near unexpected ...
1 vote
1 answer
4k views
Dockerfile cross platform TARGETARCH build not working [duplicate]
This is my Dockerfile: FROM tomcat:9 RUN apt-get update RUN apt-get install -y iputils-ping file ARG TARGETARCH RUN if ["$TARGETARCH" = "amd64"]; then \ apt-get install -y ...
0 votes
2 answers
3k views
Read a file and show the lines present in the file which do start with a certain sub-string [duplicate]
I am a beginner in shell scripting. I am trying to write a shell script which reads a file and prints out the lines in the file that starts with and ends with a certain word - say "Hi" in my case.. ...
1 vote
2 answers
2k views
String comparison does not work in Shell [duplicate]
I'm pretty new to shell programming languages. Why does the following code echo false after printing "File or directory not found."? #!/bin/sh -xu ARG_PATH="/srv/path/to/Something" if ["$ARG_PATH" = ...
0 votes
1 answer
3k views
syntax error near unexpected token `fi' Linux [duplicate]
I had to try to make a code to automate steamcmd but it always gives me the following error: syntax error near unexpected token 'fi' Code: STEAMCMDDOWN="https://steamcdn-a.akamihd.net/client/...
0 votes
3 answers
992 views
Bash script to identify running process? [duplicate]
I have put together a bash script to identify a process and echo if process is running or not accordingly. My script: #!/bin/bash var1=$(ps -ef | grep -v grep | grep crond) echo $var1 if [$var1] ...
-1 votes
1 answer
1k views
How to test if arguments were supplied and are less than 2 in BASH? [duplicate]
I am creating a script where the user must provide the first argument that is mandatory and the second argument is optional. Should throw an error if it is less than 1 or bigger than 2 arguments. ...
0 votes
3 answers
327 views
multiple if condition throws error in shell script [duplicate]
I'm using below if condition in shell script if [! -z "$failedTC"] || [-n "$failedTC"]; then echo "ITS not empaty AND NOT NULL" else echo "ITS empty or NULL" fi The above code I'm ...
0 votes
1 answer
1k views
Shell command running with error [duplicate]
When i run the below command i get the output, however it throws command not found error. I have no idea why this error appears. Any suggestions? val1 = ps -ef|grep -i active | wc -l val2 = 2 ...
0 votes
1 answer
1k views
Bash: While loop-Error " No such file or directory" [duplicate]
I have some code that doesn't work. It's says, "No such file or directory", and crashes on line 27: while [ $i < $amount] But I don't know why. Anyone? #!/bin/bash #WWGEN Aleandro small=$(echo "...
0 votes
1 answer
816 views
How to read a string variable and compare it with string constant in bash [duplicate]
I need to read a string variable and to check if it's equal to string 'qwe'. I try this code: read VAR1 if ["$VAR1" == "rwx"]; then current=$current+1 fi but terminal says [...
1 vote
1 answer
993 views
Bash script - test not working as expected [duplicate]
here is my simple script prova.sh: #!/bin/bash echo "\$# = [$#]" echo "\$1 = [$1]" if [ $# -ge 2 || $1="-h" ] then echo "###########################################...