The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need Help with the argument passing Through Command line asirohi Shell Programming and Scripting 5 09-04-2009 02:37 AM
Command Line Argument dsudipta High Level Programming 2 07-09-2009 05:19 AM
assign a command line argument and a unix command to awk variables sweta_doshi Shell Programming and Scripting 0 08-08-2008 06:54 AM
How to get the value in last command line argument??? amit_oddey21 Shell Programming and Scripting 4 05-28-2008 07:40 AM
passing a command line argument rudoraj Shell Programming and Scripting 8 06-13-2007 11:06 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 2 Weeks Ago
cynosure2009 cynosure2009 is offline
Registered User
  
 

Join Date: Nov 2009
Posts: 14
finding * in command line argument

I have to write a script to determine whether given command line argument ($1) contains "*" symbol or not, if $1 does not contains "*" symbol add it to $1, otherwise show message "Symbol is not required". For e.g. If we called this script q5 then after giving ,
$ q5 /bin
Here $1 is /bin, it should check whether "*" symbol is present or not if not it should print Required i.e. /bin/*, and if symbol present then Symbol is not required must be printed. Test your script as
$ q5 /bin
$ q5 /bin/*
  #2 (permalink)  
Old 2 Weeks Ago
frans's Avatar
frans frans is offline
Registered User
  
 

Join Date: Oct 2009
Location: Drôme, France
Posts: 91
what about the slash ?
Code:
echo -n "$1"
echo "$1" | grep -q '*' || echo '/*'
  #3 (permalink)  
Old 2 Weeks Ago
cynosure2009 cynosure2009 is offline
Registered User
  
 

Join Date: Nov 2009
Posts: 14
print /* not just *

i tries ur code ..
echo -n "$1"
echo "$1" | grep -q '*' || echo '/*'
its prints :
for sh file.sh /bin
--> /bin/*

for sh file.sh /bin/*
--> /bin/alsacard/*

so can you plzz see that and tell me the reason for that , also suggest something else..
  #4 (permalink)  
Old 2 Weeks Ago
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,843
Quote:
Originally Posted by cynosure2009 View Post
I have to write a script to determine whether given command line argument ($1) contains "*" symbol or not, if $1 does not contains "*" symbol add it to $1, otherwise show message "Symbol is not required". [...] Test your script as
$ q5 /bin
$ q5 /bin/*
Homework?

Also, if you pass an unquoted asterisk on the command line, most shell automatically expand it to all files. So /bin/* gets expanded to (exemplary)
Code:
$ q5 /bin/test /bin/true /bin/false /bin/mount ...
  #5 (permalink)  
Old 2 Weeks Ago
cynosure2009 cynosure2009 is offline
Registered User
  
 

Join Date: Nov 2009
Posts: 14
No, this is not a homework.. i was facing problem in finding difficulty in printing /bin/*
(it always prints /bin/alsacrad/* ) thats why i posted a thread
  #6 (permalink)  
Old 2 Weeks Ago
ghp ghp is offline
Registered User
  
 

Join Date: Dec 2008
Location: Zwevegem, Belgium
Posts: 13
As pludi told you, you should learn about the shell before you start writing shell-scripts.

Just try "echo /bin/*", you'll see where the alsacard comes from.

Your script will only see the * if no file corresponds to the pattern given on the command line.
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:20 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0