Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
I do this Code: set index = 1 set limit = `expr $#values - 1` while ($index <= $limit) set value = $values[$index] echo $value # calculate the size of ...
  1. #1
    Just Joined!
    Join Date
    Jul 2007
    Posts
    31

    "xargs: unmatched single quote" why this erorr message (code inside)

    I do this


    Code:
      set index = 1
        set limit = `expr $#values - 1`
        while ($index <= $limit)
    	set value = $values[$index]
    	echo $value
    	
    	# calculate the size of files within a specific period:
    	set fsize = `find  -mtime -$value -type f | xargs ls -tg | awk '{ size += $4 } END {print size}'`
            
    	# for testing:
    	echo $fsize
    	
    	# calculate the next index:
    	set nextIndex = `expr $index + 1`
    	
    	set value = $values[$nextIndex]
    	echo $value
    	
    	# calculate the size of files within the next specific period:
    	set fsize2 = `find  -mtime -$value -type f | xargs ls -tg | awk '{ size2 += $4 } END {print size2}' `
    	
    	# for testing:
    	echo $fsize2
    	
    	# calculate the difference:
    	set defsize = `expr $fsize - $fsize2`
    	
    	# for testing:
    	echo defrance
    	
    	# for testing:
    	echo $defsize
    	
    	# write into file:
    	echo "  $values[$index]  ${defsize}" >> outputISP2
    	
    	# update index:
    	set index = `expr $nextIndex`
    	
    	echo "------------------------------"
    	echo $index
    	echo "------------------------------"
        end


    it work but not properly
    give the result correct but for just 2 of 6 of array (720 ,580 ) but the other give dash "-"

    and error message
    "xargs: unmatched single quote"

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    What are the values of $value for which xargs fails? What is the find output for each of these values?
    DISTRO=Arch
    Registered Linux User #388732

  3. #3
    Just Joined!
    Join Date
    Jul 2007
    Posts
    31
    sorry I miss this line in the code
    set values = (720 580 360 270 120 90 0)

    Code:
     set values = (720 580 360 270 120 90 0)
        set index = 1
        set limit = `expr $#values - 1`
        while ($index <= $limit)
    	set value = $values[$index]
    	echo $value
    	
    	# calculate the size of files within a specific period:
    	set fsize = `find  -mtime -$value -type f | xargs ls -tg | awk '{ size += $4 } END {print size}'`
            
    	# for testing:
    	echo $fsize
    	
    	# calculate the next index:
    	set nextIndex = `expr $index + 1`
    	
    	set value = $values[$nextIndex]
    	echo $value
    	
    	# calculate the size of files within the next specific period:
    	set fsize2 = `find  -mtime -$value -type f | xargs ls -tg | awk '{ size2 += $4 } END {print size2}'`
    	
    	# for testing:
    	echo $fsize2
    	
    	# calculate the difference:
    	set defsize = `expr $fsize - $fsize2`
    	
    	# for testing:
    	echo defrance
    	
    	# for testing:
    	echo $defsize
    	
    	# write into file:
    	echo "  $values[$index]  ${defsize}" >> outputISP2
    	
    	# update index:
    	set index = `expr $nextIndex`
    	
    	echo "------------------------------"
    	echo $index
    	echo "------------------------------"
        end this line in the code
    output of find is the size of each value (720 580 360 270 120 90 0)

  4. #4
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    Is this c shell?

  5. #5
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    No, I mean the output of just:
    Code:
    find  -mtime -$value -type f
    Also, you may be interested:
    Csh Programming Considered Harmful
    DISTRO=Arch
    Registered Linux User #388732

  6. #6
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    Quote Originally Posted by Cabhan View Post
    +1

    Make life easier and script with bash. (This is Linux's default shell after all.)

  7. #7
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    Now that I think about it, the problem with your program may just be the C Shell, and may be entirely unrelated to the actual script.

    Try rewriting your script as a Bash script and see if that fixes it.
    DISTRO=Arch
    Registered Linux User #388732

  8. #8
    Just Joined!
    Join Date
    Jul 2007
    Posts
    31
    Is this c shell?
    yes it is
    Try rewriting your script as a Bash script and see if that fixes it.
    How?
    No, I mean the output of just:
    Code:

    find -mtime -$value -type f
    output is the files that modify in specific period of time which is $value (enter by user)

  9. #9
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    What I wanted was for you to post the exact output, as if you had run that command yourself. I know what it's supposed to output; I wanted to see what it actually output.

    Anyway, to rewrite it in Bash, learn how to script in Bash. A good new user guide is:
    http://tldp.org/LDP/Bash-Beginners-G...ers-Guide.html
    And a fantastic advanced guide/reference is:
    http://www.tldp.org/LDP/abs/html/

    Most things will directly translate, it's just a matter of different syntax. Bash is basically the universal Linux shell, and as described in my link about csh scripting, has many advantages over csh for scripting.
    DISTRO=Arch
    Registered Linux User #388732

  10. #10
    Just Joined!
    Join Date
    Jul 2007
    Posts
    31
    this should be the output


    720
    298436410
    580
    133149854
    differenc
    165286556
    ------------------------------
    2
    ------------------------------
    580
    133149871
    360
    2549625
    difference
    130600246
    ------------------------------
    3
    ------------------------------
    360
    2549625
    270
    1000000
    difference
    1549625
    ------------------------------
    4
    ------------------------------
    270
    1000000
    120
    900000
    difference
    100000
    ------------------------------
    5
    ------------------------------
    120
    900000
    90
    100000
    difference
    800000
    ------------------------------
    6
    ------------------------------
    90
    100000
    0
    0
    difference
    100000

    ------------------------------
    7
    ------------------------------

    720 165286556
    580 130600246
    360 1549625
    270 100000
    120 800000
    90 100000
    0 0


    I must use c shell to come with this output

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...