Find the answer to your Linux question:
Results 1 to 2 of 2
Hello I've created (as a homework) to create as many folders as told but I still need to check if the variable is a number or not : Code: #!/bin/sh ...
  1. #1
    Just Joined!
    Join Date
    Apr 2011
    Posts
    1

    Checking a variable

    Hello

    I've created (as a homework) to create as many folders as told but I still need to check if the variable is a number or not :
    Code:
    #!/bin/sh
    echo "Veuillez saisir un nombre"; read nmbr
    nmbrf=$nmbr
    while [ $nmbrf -gt 0 ]
    	do mkdir -p "foo$nmbrf"
    	nmbrf=`expr $nmbrf - 1`
    	echo "$nmbrf"
    done
    Question : how do I check that nmbr is a number or something else ? thanks in advance.

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    Homework questions are not allowed on these forums as per the rules:
    http://www.linuxforums.org/forum/lin...ums-rules.html

    As a bit of a hint: you can treat $nmbr as a string. If the string was also a valid number, what properties would it have?
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

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