Find the answer to your Linux question:
Results 1 to 3 of 3
I've tried made it like this: #! /bin/bash echo $[$#] But it seems the outer $ doesn't work, I want the result like this: ./test a f d s g ...
  1. #1
    Just Joined!
    Join Date
    Sep 2005
    Location
    China
    Posts
    37

    [SOLVED] How can I quote the last argument in the bash script?

    I've tried made it like this:
    #! /bin/bash

    echo $[$#]

    But it seems the outer $ doesn't work, I want the result like this:

    ./test a f d s g

    g

    How can I make it?

  2. #2
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    I recommend that you look at: http://www.tldp.org/LDP/abs/html/othertypesv.html around the text:
    Bracket notation for positional parameters leads to a fairly simple way of referencing the last argument passed to a script on the command line ...
    In fact, the guide http://www.tldp.org/LDP/abs/html/index.html is something that you can use to find almost every answer for bash questions ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  3. #3
    Just Joined!
    Join Date
    Sep 2005
    Location
    China
    Posts
    37
    Ok, I've got it.
    just add "eval" at the head.

    eval echo ${$#}

Posting Permissions

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