Too Many Arguments Error - shells script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Too Many Arguments Error - shells script
# 1  
Old 05-02-2013
Too Many Arguments Error - shells script

Hi,

I am getting the below error

: [: too many arguments error at the if condition start and when I print the

value of TEST, it displays two values as below
Code:
/home/xyz/out/file1.txt 
/home/xyz/out/file2.txt

Code:
if [ -f $TEST]; then
    mv $TEST $TARGETDIR/    
fi

Tried by enclosing it in double quotes "$TEST", but it doesnt enter into the if condition.

Please help on this.

Last edited by radoulov; 05-02-2013 at 05:26 PM..
# 2  
Old 05-02-2013
Use a for loop to visit each values in variable: TEST
Code:
for file in $TEST
do
        if [ -f "$file" ]
        then
                mv "$file" "${TARGETDIR}/"
        fi
done

# 3  
Old 05-02-2013
Your code says:
Code:
if [ -f $TEST]; then

It should be:
Code:
if [ -f $TEST ]; then

There has to be a space before the ]
# 4  
Old 05-02-2013
Thanks for the Resolution. It worked Smilie
# 5  
Old 05-02-2013
Yes, the [ ] is very picky about having that space there.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

UNIX shells script to echo out the date value

I appreciate if someone answer this question for my learning purpose: Given a filename structure of a COUNTRY CODE, file type, date (YYYYMMDD) and two digit attempt number with an extension of ".dat", write a UNIX shells script to echo out the date value. Example: ... (1 Reply)
Discussion started by: shumail
1 Replies

2. Shell Programming and Scripting

Run commands in a script in different shells

Hi to all, i have the following problem... i want to run three commands in a script in different shells... the first command is running always and is needed for the second on to run properly... example # Procedure 1 xterm -e exec1 arg1 arg2 # Procedure 2 xterm -e exec2 arg1 arg2 #... (6 Replies)
Discussion started by: paladinaeon
6 Replies

3. Shell Programming and Scripting

Calling a function which uses expect from a shells script

Hi all, This is the first time i am using expect. I am trying to call a function with in the shell script. The function will shh to a new server and will pass the password using expect and send. I need help in calling the fuction i am getting follaowing errors... here the script ... (8 Replies)
Discussion started by: firestar
8 Replies

4. Shell Programming and Scripting

Oracle environmental variables in shells script

Hi, Getting below error on executing the shell script which initiates sqlplus How to set oracle enviornment variables in the shell script ? With Regards (3 Replies)
Discussion started by: milink
3 Replies

5. Shell Programming and Scripting

Question regarding shells and subshells when a script is run

I have the following script running with nohup on one of my servers: #!/bin/bash #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ #set log number #i=1 #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ #Check if log exits, if so incrememnt log number up so we don't clobber #while... (8 Replies)
Discussion started by: DeCoTwc
8 Replies

6. Shell Programming and Scripting

Rename a lot of files using shells script

Hi This is the list file that i have : The files is more than this. I will rename one by one file become like this : So just change the time stamp 200906 become 200905. Is it possible using script ? Thanks (3 Replies)
Discussion started by: justbow
3 Replies

7. Shell Programming and Scripting

Using different shells in one script

Hi, Is it possible to use multiple shells in one script. There are sometimes we need to club shell specific commands in single script. for example in bash mode we use -e with echo to use Escape sequence but in ksh it is not required. How to tell a UNIX command to run in a specific shell. ... (2 Replies)
Discussion started by: sanjay1979
2 Replies

8. UNIX for Advanced & Expert Users

How to set a label/number for a function in a shells script

Can any one let me know like how cn i set an label or number for each function whihc are there in an shells script: for example cd /opt/qcom/test/ function1() function2() function3() ------- i ahe a script like this .now i want to count each of this function like 1, 2, 3,............... (3 Replies)
Discussion started by: lalitka
3 Replies

9. Shell Programming and Scripting

Validating variables in shells script

All Can you help me to validate a variable only for string and digit. That is variable should either fully alphabets or digits. Please send me result to my mail id also: REMOVED Thanx in advance Regards Deepak Xavier (1 Reply)
Discussion started by: DeepakXavier
1 Replies

10. Shell Programming and Scripting

Build script for all shells

Hi, I made a build script for the product I am working on. The script was made in the /bin/sh shell. My first line in the script (after the #! /bin/sh and following # lines ) were, if ; then /bin/sh fi; It works well with my sh shell. I run the script as sh build.sh Now I... (9 Replies)
Discussion started by: vino
9 Replies
Login or Register to Ask a Question