Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2002
    Posts
    15

    Unanswered: How to read parameter digits?

    Hi,
    I need to write a shell script to read a three digits value(including numbers and letters, such as K34 or 157....etc) from command parameter. How to deal with the parameter? Is it possible to convert the parameter string into characters and use Loop to get characters?
    Any help will be appreciated.

    Tien-Chih Wang

  2. #2
    Join Date
    Feb 2002
    Posts
    2,232
    Can you submit an example of what you are trying to do ? What do you want to do with the 3 character strings ?

  3. #3
    Join Date
    Feb 2002
    Posts
    15
    I need to write a makefile shell script and the first pararmeter will be the release number. The release number must consist of three digit numbers(including either number or letter, such as 001, 002, or 3KH, A58). What I need to do is only to judge if the digits equals three and whether they belongs to either Number or Letters. That's it. It shouldn't be too difficult, but I still cannot find the way out.

    Any help will be appreciated.

    TC Wang

  4. #4
    Join Date
    Apr 2002
    Posts
    17
    You can check the number of letters in the variable using "wc -c":
    (This will always return the number of characters +1, line ending character)

    [oracle@oradb02 oracle]$ echo "K12" | wc -c
    4
    [oracle@oradb02 oracle]$ echo "K123" | wc -c
    5


    You can split the string to characters using "cut -c":

    [oracle@oradb02 oracle]$ echo "K12" | cut -c1
    K
    [oracle@oradb02 oracle]$ echo "K12" | cut -c2
    1
    [oracle@oradb02 oracle]$ echo "K12" | cut -c3
    2

    You can test the characters as follows:

    [oracle@oradb02 oracle]$ if echo "K12" | cut -c1 | grep [0-9] >/dev/null; then
    > echo "NUMBER"
    > elif echo "K12" | cut -c1 | grep [A-z] >/dev/null; then
    > echo "LETTER"
    > fi
    NUMBER

    Hope this is helpful,

    Geoff

  5. #5
    Join Date
    Feb 2002
    Posts
    15
    Thanks. It really helps.

    Tien-Chih Wang

Posting Permissions

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