Can a string be a command line argument?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can a string be a command line argument?
# 1  
Old 03-11-2012
Can a string be a command line argument?

I would like to use a string as a command line this possible using TCSH? For example say my script is called TEST and I would like to pass a string into my script stating why the test failed.


TEST "Failed due to missing statement"
# 2  
Old 03-11-2012

In the shell do;

export TEST="Failed due to missing statement"
./scriptname ${TEST}

Hope that helps.


# 3  
Old 03-11-2012
please post exactly what you are doing.
script name,sourcecode and the parameter you are passing.
May be you have issue with test operator.
# 4  
Old 03-11-2012
Thanks for the reply Dave...I am pretty new to this so I'm not following your answer. If you could explain or maybe you misunderstood my question....below is another hack at explaining myself.

I would like the user to be able to run the script named TEST and then for the command line argument enter whatever they want. Then I want to use this string in my script. I know how to get a script argument when its a single word...but not for a string. So for example the user would enter:

TEST "whatever text they desire"
# 5  
Old 03-11-2012
Hi thibodc,

Not so hard, the format would be as follows;

./scriptname string

If the string has spaces in it then it would have to be enclosed in quotes like this.

./scriptname "this is a string"

To use in the script you would reference $1 the first command line argument after the scriptname.

As an example;

echo $1

Hope that this helps.


Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Command line argument

Hi Guys, I'm trying to work out how to add a command line argument inside single quotes. Would anyone be able to help please as I'm going mad :) I want to be able to place the filename on command line and it then be used in a script but it needs to have quotes surrounding it. Thanks in... (4 Replies)
Discussion started by: mutley2202
4 Replies

2. Shell Programming and Scripting

Specify an entire UNIX command as a command line argument

I'm trying to write a bash script called YN that looks like the following YN "Specify a question" "doThis" "doThat" where "doThis" will be executed if the answer is "y", otherwise "doThat". For example YN "Do you want to list the file dog?" "ls -al dog" "" Here's my attempt... (3 Replies)
Discussion started by: LeoKSimon
3 Replies

3. Shell Programming and Scripting

command line argument - perl

how do i check if a command line argument is -g? for example, if command line argument equals "-g" { print "Goodbye \n"; } else { print "Welcome to the program! \n"; } (1 Reply)
Discussion started by: bshell_1214
1 Replies

4. Shell Programming and Scripting

command-line line 0: Missing yes/no argument

Hi Guys When I run the below command ssh -o 'PasswordAuthentication yes' -o 'PreferredAuthentications publickey' -i $HOME/.ssh/id_dsa Server_Name I found the below error ommand-line line 0: Missing yes/no argument Kindly help me to sort out Double post, continued... (0 Replies)
Discussion started by: Pratik4891
0 Replies

5. Programming

Command Line Argument

Hi, I have a very simple C program which will run in UNIX. When i am passing * as the command line argument, i am gettig the below output. Program: #include <stdio.h> #include "mylibrary.h" int **environ; int main(int argc,char *argv) { int i; printf("\nHello... (2 Replies)
Discussion started by: dsudipta
2 Replies

6. Shell Programming and Scripting

assign a command line argument and a unix command to awk variables

Hi , I have a piece of code ...wherein I need to assign the following ... 1) A command line argument to a variable e.g origCount=ARGV 2) A unix command to a variable e.g result=`wc -l testFile.txt` in my awk shell script When I do this : print "origCount" origCount --> I get the... (0 Replies)
Discussion started by: sweta_doshi
0 Replies

7. Shell Programming and Scripting

How to get the value in last command line argument???

Say I want to get the value of last command line argument using the value in $# (or some other way if u can suggest) how do I do it?? $"$#" `$"$#"` These don't work :( (4 Replies)
Discussion started by: amit_oddey21
4 Replies

8. Shell Programming and Scripting

passing a command line argument

I have a shell script which does the encryption of a file where i am passing the file name as a command line argument,but later on the script waits on the screen to enter Y or N what is the command i should be using on the shell script #!/bin/bash -x outfilename=file.out echo... (8 Replies)
Discussion started by: rudoraj
8 Replies

9. UNIX for Dummies Questions & Answers

array as command line argument !!!!

hello, can any help me how to can pass array as command line argument in korn shell. also how to read a array from command line. thanks spandu (2 Replies)
Discussion started by: spandu
2 Replies

10. UNIX for Dummies Questions & Answers

command line argument parsing

how to parse the command line argument to look for '@' sign and the following with '.'. In my shell script one of the argument passed is email address. I want to parse this email address to look for correct format. has '@' sign and followed by a '.' to be more... (1 Reply)
Discussion started by: rmjoe
1 Replies
Login or Register to Ask a Question

Featured Tech Videos