Single char


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Single char
# 1  
Old 03-13-2013
Single char

Task 2:

When Im tring script called char that checks a single character on the
command line, c. If the character is a digit, digit is displayed. If the
character is an upper or lowercase alphabetic character, letter is
displayed. Otherwise, other is displayed. Have the script print an
error message if the argument c is more than one character in length.

How to pass the alphabet characters as a argument in case and in if block? How to pass multiple numbers in a single case?
Help!! to correct the code

Code:
#!/bin/ksh
 
c=$1
if [[ c -le 9 ]]
then
echo "Proceed "
elif [[ c -eq a-z ]]
then
echo "alphabet"
else
echo "More than one char in length"
fi
 
case $1 in
 
1-9) echo "The value is a number"
;;
a-z) echo "the value is a alphabet"
;;
*) echo "Other"
;;
esac

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Invalid conversion from char* to char

Pointers are seeming to get the best of me and I get that error in my program. Here is the code #include <stdio.h> #include <stdlib.h> #include <string.h> #define REPORTHEADING1 " Employee Pay Hours Gross Tax Net\n" #define REPORTHEADING2 " Name ... (1 Reply)
Discussion started by: Plum
1 Replies

2. UNIX for Dummies Questions & Answers

Replacing multiple special chars with single char

Hi I've a string . And i need to replace set of characters with a single character Means .. or . or ... and so on should be replaced with single % character Irrespective of number of dots in between the characters , those should be replaced with single % All the above strings should be... (3 Replies)
Discussion started by: smile689
3 Replies

3. Shell Programming and Scripting

Formatting File having big single line into 95 Char Per Line

Hi All, I have 4 big files which contains one big line containing formatted character records, I need to format each file in such way that each File will have 95 Characters per line. Last line of each file will have newline character at end. Before:- File Name:- File1.dat 102 121340560... (10 Replies)
Discussion started by: lancesunny
10 Replies

4. Programming

error: invalid conversion from ‘const char*’ to ‘char*’

Compiling xpp (The X Printing Panel) on SL6 (RHEL6 essentially): xpp.cxx: In constructor ‘printFiles::printFiles(int, char**, int&)’: xpp.cxx:200: error: invalid conversion from ‘const char*’ to ‘char*’ The same error with all c++ constructors - gcc 4.4.4. If anyone can throw any light on... (8 Replies)
Discussion started by: GSO
8 Replies

5. Shell Programming and Scripting

Help substituting text in a file having a single line but no newline char

Hello, Need help substituting a particular word in a file having a single line but no newline character at the end. I was trying to use sed but it doesn't work probably because there is no newline char at the end of the line. $ cat hlq_detail /outputs/alvan23/PDFs/bills $ cat... (5 Replies)
Discussion started by: Shan_u2005
5 Replies

6. UNIX for Dummies Questions & Answers

tab char appearing as single space?

I'm trying to run a script which will ssh to several other servers (All Solaris 10) and execute a sar -f command to get each server's CPU usage for a given hour. It kinda works OK but I just can't figure out how to separate the returned fields with a Tab character. I've done lots of searching... (2 Replies)
Discussion started by: jake657
2 Replies

7. Programming

concat const char * with char *

hello everybody! i have aproblem! i dont know how to concatenate const char* with char const char *buffer; char *b; sprintf(b,"result.txt"); strcat(buffer,b); thanx in advance (4 Replies)
Discussion started by: nicos
4 Replies

8. UNIX for Dummies Questions & Answers

how2 get single char from keyboard w/o enter

I am writing a bash shell menu and would like to get a char immediately after a key is pressed. This script does not work but should give you an idea of what I am trying to do.... Thanks for the help #! /bin/bash ANSWER="" echo -en "Choose item...\n" until do $ANSWER = $STDIN ... (2 Replies)
Discussion started by: jwzumwalt
2 Replies

9. Programming

Adding a single char to a char pointer.

Hello, I'm trying to write a method which will return the extension of a file given the file's name, e.g. test.txt should return txt. I'm using C so am limited to char pointers and arrays. Here is the code as I have it: char* getext(char *file) { char *extension; int i, j;... (5 Replies)
Discussion started by: pallak7
5 Replies

10. Shell Programming and Scripting

How to replace any char with newline char.

Hi, How to replace any character in a file with a newline character using sed .. Ex: To replace ',' with newline Input: abcd,efgh,ijkl,mnop Output: abcd efgh ijkl mnop Thnx in advance. Regards, Sasidhar (5 Replies)
Discussion started by: mightysam
5 Replies
Login or Register to Ask a Question
vprintf(3int)															     vprintf(3int)

Name
       vprintf, vfprintf, vsprintf - print formatted output of a varargs argument list

Syntax
       #include <stdio.h>
       #include <varargs.h>

       int vprintf ( format, ap )
       char *format;
       va list ap;

       int vfprintf ( stream, format, ap )
       FILE *stream;
       char *format;
       va list ap;

       int vsprintf ( s, format, ap )
       char *s, *format;
       va list ap;

Description
       The international functions and are similar to the standard I/O functions.

       Likewise,  the  vprintf functions are similar to the printf functions except they are called with an argument list as defined by instead of
       with a variable number of arguments.

       The international functions allow you to use the %digit$ conversion character in place of the % character  you  use  in	the  standard  I/O
       functions.   The digit is a decimal digit n from 1 to 9.  The international functions apply conversions to the nth argument in the argument
       list, rather than to the next unused argument.

       You can use the % conversion character in the international functions.  However, you cannot mix the % conversion character with the %digit$
       conversion character in a single call.

       You  can  indicate  a  field  width or precision by an asterisk (*) instead of a digit string in format strings containing the % conversion
       character. If you use an asterisk, you can supply an integer arg that specifies the field width or precision.  In format strings containing
       the  %digit$  conversion character, you can indicate field width or precision by the sequence *digit$.  You use a decimal digit from 1 to 9
       to indicate which argument contains an integer that specifies the field width or precision.

       The conversion characters and their meanings are identical to

       You must use each digit argument at least once.

Examples
       #include <stdio.h>
       #include <varargs.h>

       main()
       {
       char *function_name = "vpr";
       char *arg1 = "hello world";
       int arg2 = 2;
       char *arg3 = "study";

       char *i18nfmt = "%1$s %3$d
";

       test(function_name, i18nfmt, arg1, arg2, arg3);
       }

       test(va_alist)
       va_dcl
       {
       va_list args;
       char *fmt;
       char string[1024];

       va_start(args);

       (void)printf("function %s: ", va_arg(args, char *));

       fmt = va_arg(args, char *);

       (void)vprintf(fmt, args);

       va_end(args);
       }

See Also
       setlocale(3), scanf(3int), printf(3s), printf(3int), vprintf(3s), putc(3s), scanf(3s), stdio(3s), varargs(3)
       Guide to Developing International Software

																     vprintf(3int)