Bash script too many arg's


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash script too many arg's
# 1  
Old 10-15-2014
Bash script too many arg's

I have a simple bash script on RHEL that works fine when there is one file but when it finds multiple files of same condition I get too many args error.

Code:
for i in *
do
        if [ ! -f "$i" ];then
                echo "no files to move"
                exit 0
        fi
         if [ "$i" = *02.DAT ]; then
                mv $i $CD/somefolder/
        fi

# 2  
Old 10-15-2014
Its system issue whats the output of this command

Code:
getconf ARG_MAX

# 3  
Old 10-15-2014
Actually, I think this is the problem:

Code:
if [ "$i" = *02.DAT ]; then

*02.DAT does not do what you think it does here. If there's any filenames in the current folder matching it, it expands into a list of those names.

I believe you intended this:

Code:
if [[ "$i" == *02.DAT ]] ; then

double-equal in double brackets wildcards against $i instead of the current directory.
# 4  
Old 10-15-2014
you guys are great. Corona your modification has it working now. Just so I can learn something what are the extra brackets and equals doing?

Just because of my interest this is what the max is set to 2621440
# 5  
Old 10-15-2014
Another way would be:
Code:
for i in *02.DAT
do
    if [ -f "$i" ]; then
        mv -- "$i" "$CD/somefolder/"
    else
        echo "no files to move"
    fi
done


Last edited by Scrutinizer; 10-15-2014 at 03:39 PM..
This User Gave Thanks to Scrutinizer For This Post:
# 6  
Old 10-15-2014
# 7  
Old 10-15-2014
Actualy, with the use of *02.dat one could drop the check for its existence, as it should only be listed because it exists.
Thus it could be like:
Code:
for f in *02.dat;do mv "$f" "$CD/somefolder/"|| echo "Move failed with code: $?";done

hth
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed ? Is there any way to get the script names for the process command ? --- Post updated at 08:39 AM --- in KSH (Korn Shell), my command output shows the script names but when run in the Bash Shell... (3 Replies)
Discussion started by: i4ismail
3 Replies

2. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

3. Shell Programming and Scripting

ksh script throwing arg list too long for mv cp wc - everything

i have a ksh script which internally calls another ksh script. this inner script has simple commands like shown in the code window. In the script im trying to do a mv - it fails with arg list too long. then i try to perform cp and cat - and both are failing with similar error. :wall: How is... (4 Replies)
Discussion started by: nyc68
4 Replies

4. Shell Programming and Scripting

script arg or parameters limitation

Hi, I would like to ask some info on the script arguments/parameters. Does script arguments had limitation like inside or deep inside the loop in which it will not function as it use to be. as an example: $2 not working command2 () { for log in $LOG{1,2,3} do if && ; then echo... (2 Replies)
Discussion started by: jao_madn
2 Replies

5. UNIX for Dummies Questions & Answers

Space in a arg

Hi, When i am running a script it considers the below as mulitple arguments. There is any command which can ignore the spaces. I tried by using sed like below to ignore but it doesnt work. sed 's/ /\\ /g'100% Haddock Fillets Battered 500G-small.gif ~vino (3 Replies)
Discussion started by: vino_hymi
3 Replies

6. Programming

warning: int format,pid_t arg (arg 2)

I try following code under Solaris10,like follows: int glob = 6; int main(void) { int var; pid_t pid; var = 88; printf("before vfork\n"); if ((pid = vfork()) < 0) { err_sys("vfork error"); } else if (pid == 0) { glob++; var++; _exit(0); } ... (1 Reply)
Discussion started by: konvalo
1 Replies

7. Shell Programming and Scripting

How to pass an array as arg to a script..

Hi, Please guide to pass an array as a arg to a script... for example, I have a script small.sh to find the small no of given arg as below... #! /bin/sh # this script is for finding the small number set -A arr_no_updates small=$1 i=1 for arr in $@ do if (3 Replies)
Discussion started by: little_wonder
3 Replies

8. Shell Programming and Scripting

how to make your bash script run on a machine with csh and bash

hi, i have a script that runs on bash and would like to run it on a machine that has csh and bash. the default setting on that machine is csh. i dont want to change my code to run it with a csh shell. is there any way i can run the script (written in bash) on this machine? in other words is there... (3 Replies)
Discussion started by: npatwardhan
3 Replies

9. Shell Programming and Scripting

passing variable from bash to perl from bash script

Hi All, I need to pass a variable to perl script from bash script, where in perl i am using if condition. Here is the cmd what i am using in perl FROM_DATE="06/05/2008" TO_DATE="07/05/2008" "perl -ne ' print if ( $_ >="$FROM_DATE" && $_ <= "$TO_DATE" ) ' filename" filename has... (10 Replies)
Discussion started by: arsidh
10 Replies
Login or Register to Ask a Question