Linked Questions
201 questions linked to/from Why should there be spaces around '[' and ']' in Bash?
94 votes
5 answers
154k views
How do you call a function defined in .bashrc from the shell? [duplicate]
In my .bashrc, I have a function called hello: function hello() { echo "Hello, $1!" } I want to be able to invoke hello() from the shell as follows: $ hello Lloyd And get the output: > Hello, ...
48 votes
6 answers
302k views
Integer expression expected error in shell script [duplicate]
I'm a newbie to shell scripts so I have a question. What Im doing wrong in this code? #!/bin/bash echo " Write in your age: " read age if [ "$age" -le "7"] -o [ "$age" -ge " 65" ] then echo " You can ...
13 votes
1 answer
44k views
"[0: command not found" in Bash [duplicate]
I am trying to get the array in the while-loop and need to update the value in array too. Below is my code what I have tried. I get this error [0: command not found #!/bin/bash i=0 while [$i -le "{#...
10 votes
1 answer
4k views
Shell spacing in square brackets [duplicate]
As a beginner, I did not find answered anywhere, the rules about spacing (grammar) and parsing. For example. Can I do if [$# -eq 2] ; then llll fi or must I always have a blank or two ...
0 votes
6 answers
5k views
bash shell script syntax error [duplicate]
I wrote a function in bash script. However, it's complaining about syntax. I really can't see what is it..... the error message is [: missing `]' addem() { if [ $# -eq 0] || [ $# -gt 2 ] ...
2 votes
2 answers
16k views
Bash script command not found error in while loop [duplicate]
I have problem and cant still handle with it. :( Here is my code declare -i disk_usage_rate=$(df -h /appdata/SCT_CDR | cut -d '%' -f 1 | awk 'NR==2{print $5}') while ["$disk_usage_rate" -gt 80] do ....
5 votes
2 answers
5k views
bash, command not found [duplicate]
i'm having trouble fixing the error in this bash script, I seriously have no idea what I did wrong, any help is appreciated thanks [centoslive@livecd ~]$ sh ListFich.sh test Synthese, Question 2 ...
-4 votes
2 answers
10k views
How To Compare Number Of Lines In 2 Files Using IF/Then Bash Command [duplicate]
I would like to compare the line counts of two separate files. While I have tried using wc -l in the comparison, I'm struggling to get it working properly. I have: if [ "$(wc -l file1.txt)" == "$(wc ...
2 votes
1 answer
12k views
[-f: Command not found, Bash script does file exist [duplicate]
I'm having an issue with a script that I am trying to program. Narrowed down and simplified code and it gives an error that command is not found. If i do "test -f file" in command line it returns ...
2 votes
1 answer
21k views
Bash script for loop with if-else statement [duplicate]
I'm trying to write a bash script that imports all users and for each account execute some action. a="some account" b="some account" #... so on USERS = #get imported for ACCOUNT in $USERS; do ...
3 votes
1 answer
11k views
Conditional binary operator expected: syntax error near `$1' [duplicate]
I am trying to run simple code block. It gives error on fourth line as "syntax error near `$1'" =~ means Matches Regular Expression How should I use '$1' variable with this operator? Here is my ...
3 votes
2 answers
7k views
Bash shell script: "syntax error near unexpected token `fi'" [duplicate]
I have a section of code in a bash shell script that looks like this, with a series of consecutive conditionals: #do January first, no matter what awk '$4 == "Jan" {print $0}' < last-output.txt | ...
1 vote
2 answers
10k views
syntax error near unexpected token `then' [duplicate]
I created a script that helps administrators add and remove users from text file instead of doing it manually. I ran into this error and i'm having trouble solving it. [ec2-user@ip-172-31-15-55 ~]$ ./...
1 vote
1 answer
6k views
how to exit if there is no argument in bash shell script? [duplicate]
i have written code to count the number of files and directories, but im struggling to make it exit if no argument is given. here is what i have right now, with the first is statement being the ...
0 votes
2 answers
11k views
how to run an exe using shell script [duplicate]
I have an exe which takes 2 parameters both are csv as below splitline.exe /dir/file1.csv /dir1/file2.csv, this basically splits the lines in the input file to 2 lines in the output file.So,I wrote a ...