[: too many arguments error in bash script

You are writing shell script and got too many arguments error

While writing bash script, if you got this error, check where you are making expression test like in

if [ $somevar = "value"]; then
..

if the $somevar is something you are getting it from another command [ say grep or ls] which happen to return a lot of results that are separated by space or something you end up having it being

if [file1 file 2 file 3 = "value"]; then

The easiest solution for this is to enclose the variable in double quote like

if [ -n  "$somevar"]; then
some more commands goes here

Click here to see more on bash

Recommended: Solving Algorithms

Given array of numbers, find k complementary numbers – those which would add up to k. Here is how to solve it

How would you find three numbers that would add to number T from the list of numbers? Compare your solution with this one

With limited memory, and lots of storage, find the missing numbers from a file containing billion numbers in efficient way. Check the attempted solution for it

See how you would solve these known algorithm problems

Array reversal in Recurrsion

testing k complementary pairs algorithm with junit

Changing decimal number to its binary equivalent

Finding missing numbers from billion sequential number list file

binary tree problems with solution

Find the first occurence of number in the sorted array

Find the pairs that makes K Complementary in the given array java solution

Check if there are three numbers a, b, c giving a total T from array A

Implementing tokenizer and adding tokens to the linked list

Kadane’s algorithm in C – Dynamic Programming

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*