Sponsored Content
Full Discussion: command line arguments
Top Forums Shell Programming and Scripting command line arguments Post 302503676 by vins_89 on Friday 11th of March 2011 09:44:25 AM
Old 03-11-2011
command line arguments

hi,,,,

I want to create a command prompt, for example "prompt>", so my prompt need to handle commands, for example "prompt>cmd", so i want to know how to get arguments for my own commands cmd, i.e. default argc should contain arguments count and argv should point to the argument vector i.e, for example "prompt>cmd arg1 arg2" now argc should contain 2 n argv should point to arguments,,,so wats may be the solution for this????

thanks in advance for the solution Smilie
 

10 More Discussions You Might Find Interesting

1. Programming

command line arguments

Hi How to pass multi line text as a command line argument to a program. (i.e) ./a.out hi this is sample 0 file1 where hi this is sample should be stored in argv 0 in argv and so on... (3 Replies)
Discussion started by: bankpro
3 Replies

2. UNIX for Dummies Questions & Answers

arguments in command line

Hi all, How many arguments can we pass while testing a prgm at command line.. I encountered an issue while passing 10 arguments. For $10 its taking argument passed for $1 followed by 'zero'. can we pass more than 9 arguments /Is there any other way. Thanks, rrs (6 Replies)
Discussion started by: rrs
6 Replies

3. Shell Programming and Scripting

command line arguments

-------------------------------------------------------------------------------- I have this while loop and at the end I am trying to get it to tell me the last argument I entered. And with it like this all I get is the sentence with no value for $1. Now I tried moving done after the sentence... (1 Reply)
Discussion started by: skooly5
1 Replies

4. Shell Programming and Scripting

Getting error in command line arguments

Hi, When i am running the following script 1.sh (without giving the command line arguments) then i am getting the following error. if then echo "UID and PWD are correct" elif then echo "Either UID or PWD is wrong. Please check your UID and PWD" else echo "UID and PWD can't be blank"... (9 Replies)
Discussion started by: sunitachoudhury
9 Replies

5. UNIX for Dummies Questions & Answers

Command line arguments.

I am working on a script wherein i need the user to enter the Build ID for eg:the command line will show enter the build ID Now on entering the build ID it should be assigned to @ARGV. How can this be done.? (1 Reply)
Discussion started by: Varghese
1 Replies

6. UNIX for Dummies Questions & Answers

getopts - command line arguments

Hi, I'm having problems with a script where I wanted every single option specified in the command line to have an argument taken with it, but for some reason only d works in the code I will be showing below. For example if I did ./thisfile -a something it would come up with "a chosen with " as... (2 Replies)
Discussion started by: IceX
2 Replies

7. Shell Programming and Scripting

Maximum command line arguments

Hi, Can anyone please help me to know what is the maximum number of command line arguments that we can pass in unix shell script? Thanks in advance, Punitha.S (2 Replies)
Discussion started by: puni
2 Replies

8. UNIX for Dummies Questions & Answers

command line arguments

hi, can someone how to accept command line arguments as a variable using in script? like: ./scriptname arguments by accept arguments, I can use it in my script? thx! (1 Reply)
Discussion started by: ikeQ
1 Replies

9. Shell Programming and Scripting

Command Line Arguments - not working

I am new to the world of Unix and shell scripting and have been trying to get the following simple script to work: #!/bin/bash echo "what is your age?" echo "you are $1 years old"I want to be able to enter my age on the command line, when prompted, and it return the... (1 Reply)
Discussion started by: meursault
1 Replies

10. Shell Programming and Scripting

Command line arguments for addition

Hi all, I am trying to write a code for addition of n numbers which will be passed by the user as command line arguments. I wrote the following code. add=0 for (( i = 1 ; i <= $# ; i++ )) do add=`expr $i + $add` done #echo "sum is : $add" input : $./add.sh 12 32 14... (7 Replies)
Discussion started by: PranavEcstasy
7 Replies
SHQUOTE(3)						   BSD Library Functions Manual 						SHQUOTE(3)

NAME
shquote, shquotev -- quote argument strings for use with the shell LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <stdlib.h> size_t shquote(const char *arg, char *buf, size_t bufsize); size_t shquotev(int argc, char * const *argv, char *buf, size_t bufsize); DESCRIPTION
The shquote() and shquotev() functions copy strings and transform the copies by adding shell escape and quoting characters. They are used to encapsulate arguments to be included in command strings passed to the system() and popen() functions, so that the arguments will have the correct values after being evaluated by the shell. The exact method of quoting and escaping may vary, and is intended to match the conventions of the shell used by system() and popen(). It may not match the conventions used by other shells. In this implementation, the following transformation is applied to each input string: o it is surrounded by single quotes ('), o any single quotes in the input are escaped by replacing them with the four-character sequence: ''', and o extraneous pairs of single quotes (caused by multiple adjacent single quotes in the input string, or by single quotes at the begin- ning or end of the input string) are elided. The shquote() function transforms the string specified by its arg argument, and places the result into the memory pointed to by buf. The shquotev() function transforms each of the argc strings specified by the array argv independently. The transformed strings are placed in the memory pointed to by buf, separated by spaces. It does not modify the pointer array specified by argv or the strings pointed to by the pointers in the array. Both functions write up to bufsize - 1 characters of output into the buffer pointed to by buf, then add a NUL character to terminate the out- put string. If bufsize is given as zero, the buf parameter is ignored and no output is written. RETURN VALUES
The shquote() and shquotev() functions return the number of characters necessary to hold the result from operating on their input strings, not including the terminating NUL. That is, they return the length of the string that would have been written to the output buffer, if it were large enough. If an error occurs during processing, the value ((size_t)-1) is returned and errno is set appropriately. EXAMPLES
The following code fragment demonstrates how you might use shquotev() to construct a command string to be used with system(). The command uses an environment variable (which will be expanded by the shell) to determine the actual program to run. Note that the environment vari- able may be expanded by the shell into multiple words. The first word of the expansion will be used by the shell as the name of the program to run, and the rest will be passed as arguments to the program. char **argv, c, *cmd; size_t cmdlen, len, qlen; int argc; ... /* * Size buffer to hold the command string, and allocate it. * Buffer of length one given to snprintf() for portability. */ cmdlen = snprintf(&c, 1, "${PROG-%s} ", PROG_DEFAULT); qlen = shquotev(argc, argv, NULL, 0); if (qlen == (size_t)-1) { ... } cmdlen += qlen + 1; cmd = malloc(cmdlen); if (cmd == NULL) { ... } /* Create the command string. */ len = snprintf(cmd, cmdlen, "${PROG-%s} ", PROG_DEFAULT); qlen = shquotev(argc, argv, cmd + len, cmdlen - len); if (qlen == (size_t)-1) { /* Should not ever happen. */ ... } len += qlen; /* "cmd" can now be passed to system(). */ The following example shows how you would implement the same functionality using the shquote() function directly. char **argv, c, *cmd; size_t cmdlen, len, qlen; int argc, i; ... /* * Size buffer to hold the command string, and allocate it. * Buffer of length one given to snprintf() for portability. */ cmdlen = snprintf(&c, 1, "${PROG-%s} ", PROG_DEFAULT); for (i = 0; i < argc; i++) { qlen = shquote(argv[i], NULL, 0); if (qlen == (size_t)-1) { ... } cmdlen += qlen + 1; } cmd = malloc(cmdlen); if (cmd == NULL) { ... } /* Start the command string with the env var reference. */ len = snprintf(cmd, cmdlen, "${PROG-%s} ", PROG_DEFAULT); /* Quote all of the arguments when copying them. */ for (i = 0; i < argc; i++) { qlen = shquote(argv[i], cmd + len, cmdlen - len); if (qlen == (size_t)-1) { /* Should not ever happen. */ ... } len += qlen; cmd[len++] = ' '; } cmd[--len] = ''; /* "cmd" can now be passed to system(). */ SEE ALSO
sh(1), popen(3), system(3) BUGS
This implementation does not currently handle strings containing multibyte characters properly. To address this issue, /bin/sh (the shell used by system() and popen()) must first be fixed to handle multibyte characters. When that has been done, these functions can have multi- byte character support enabled. BSD
September 7, 2008 BSD
All times are GMT -4. The time now is 06:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy