space not allowed in input


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting space not allowed in input
# 1  
Old 08-29-2011
space not allowed in input

I have this script. (options is an array) It works fine. It responds fine to all items that are stored in the array. But when I press spacebar when I am asked for input. It will not give an error only run the function again. While I put : || [[ $i = " " ]] in the script to capture the space. What am I missing to avoid that only space is entered in the response or space[any characters]

Code:
bla()
{
echo "Choose"
echo
typeset -x PS3="Command: "
select i in ${options[*]}
do

  if [[ x"$i" == "x" ]] || [[ $i == " " ]]
  then
  print - Invalid option -  ; bla
  fi
  print "Selection item $REPLY: $i" ; exit 0
done
}
bla


Last edited by pludi; 08-29-2011 at 07:55 AM.. Reason: missed a =
# 2  
Old 08-29-2011
comparison needs double equal symbol (==)
Code:
 
[[ $i == " " ]]

# 3  
Old 08-29-2011
sorry, that was typo. But still when I enter [space] it is just rerunning the function.
I think it is because $i is not set when enter a space (or even multiple space)
only when entering something it will run the funtion fine...
# 4  
Old 08-29-2011
use

Code:
 
 "$i" == " "

or

Code:
 
"$i" -eq " "

# 5  
Old 08-29-2011
still not working...
# 6  
Old 08-29-2011
Maybe it's because space is default field separator.
Try setting different IFS at the beginning, and restore it at end:
Code:
#!/bin/bash

SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

[here goes all script]

IFS=$SAVEIFS

# 7  
Old 08-29-2011
sorry did not mention:

#!/usr/bin/ksh Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Space in input filename with pipe

Hello, Normally below script works, could you please comment out what could be the reason of failure if there are spaces in input filename: script.sh #!/bin/bash cd /home/hts/.hts/tvh/ file="$1 $2 $3 $4" read -d $'\x04' name < "$file" /usr/bin/ffmpeg -i ""$name"" -vcodec copy -preset... (1 Reply)
Discussion started by: baris35
1 Replies

2. Post Here to Contact Site Administrators and Moderators

Not allowed to post URLs

Hi, I tried to post some perl code for discussion (wrapped in swaddling . However, a regex has an escaped backslash so the forum parser sees it as an URL? Had the same experience with the sample data that I tried to provide for the same discussion. It contains emails addresses,... (1 Reply)
Discussion started by: msutfin
1 Replies

3. HP-UX

Are you allowed to use the same vswitch for 2 separate HPVMs?

Can you use the same vswitch for multiple HPVMs? The reason I ask is because I created a vswitch and assigned it to one hpvm, and I was able to get it on the network. Then I created a second hpvm and used the same vswitch, and I am able to ssh/sftp TO the second hpvm, but I am unable to ping... (8 Replies)
Discussion started by: bstring
8 Replies

4. Shell Programming and Scripting

function terminating if i give input as space or no input and enter

HI i have written a script to ask input from the user. this script should promote the user for y/n input. if user enters anyother input then y/n the script promotes him again. this below code is working fine for all the cases. except for space and enter " if i give space and enter it is... (2 Replies)
Discussion started by: BHASKARREDDY006
2 Replies

5. Programming

How to get address space size that a process is allowed to use

Hi All, From C++, I just want to find the address space size that a process is allowed to use. For ex, in 32 bit OS the allowed address space is 4GB and in 64 bit OS I guess this is 16GB or more. I jsut want to find it in my C++ project. Is there any API calls that gives me such information.... (2 Replies)
Discussion started by: Sendil Kumar
2 Replies

6. AIX

rlogin always allowed ?

Hello, Could someone explain why rlogin is allways allowed in my AIX 6.1 boxes, whatever user I use ? According to documentation it should work only when .rhosts (or hosts.equiv) is properly set. But even these files do not exist - access is allowed. If I use rsh(with specified command) it... (2 Replies)
Discussion started by: vilius
2 Replies

7. Web Development

access to my server is always allowed

Hi, I can't deny the access to my server. if I visit http://localhost I can always see all the files. Why ? <Directory /> Options FollowSymLinks AllowOverride None Order allow,deny Deny from All </Directory> <Directory "/Users/aneuryzma/Sites"> (4 Replies)
Discussion started by: aneuryzma
4 Replies

8. Shell Programming and Scripting

File path with space as external input to the program

Hello I am getting error when the file (Folder or Application) path having space is given as external input to the shell program. It works fine for the files which has no spaces in the file name Thans, (5 Replies)
Discussion started by: keshav.murthy@r
5 Replies

9. Shell Programming and Scripting

Consecutive spaces within input being converted to single space

I'm reading from a file that is semi-colon delimited. One of the fields contains 2 spaces separating the first and last name (4th field in - "JOHN<space><space> DOE"): e.g. TORONTO;ONTARIO;1 YONGE STREET;JOHN DOE;CANADA When I read this record and either echo/print to screen or write to... (4 Replies)
Discussion started by: NinersFan
4 Replies

10. UNIX for Dummies Questions & Answers

Ldap dn chars allowed

Hi Is it possible to add the following to an ldif entry: dn=estmmartín i.e Note the charchter 'í' Thanks in advance (3 Replies)
Discussion started by: tom123
3 Replies
Login or Register to Ask a Question