nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

example for string connect to a command.

This is a discussion on example for string connect to a command. within the Shell scripting forums, part of the Development/Scripting category; here is a example for str+str=command, ###script 1### str1='ls' str2='-l' str3="$str1 $str2" #notice the formular $str3 ###script 2### if debugout=true ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 02-22-2005, 12:52 PM
Junior Member
User
 
Join Date: Feb 2005
Posts: 8
Rep Power: 0
ryan
Send a message via MSN to ryan
Default example for string connect to a command.

here is a example for str+str=command,


###script 1###
str1='ls'
str2='-l'
str3="$str1 $str2" #notice the formular
$str3


###script 2###
if debugout=true ; then
str1=' '
else
str1='#'
fi
str2='echo this is debug output'
str3="$str1 $str2"
$str3

but actually, when str1=#, I got following err "# is not recognized"

who have any idea ,pls share with me. THanks vivi[/quote]
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-22-2005, 01:23 PM
Administrator
Site Admin
 
Join Date: Jan 1970
Posts: 43
Rep Power: 10
vivek has disabled reputation
Default

I think you need something as follows:

Code:
debug="0" # 0 - true, nonzero = false
str1='ls'
str2='-l'
str3="$str1 $str2" #notice the formular
[ "$debug" == "0" ] && echo "$str1 $str2 $str3" || $str3
if debug is zero then display the values of all three variables str1,str2,str3 else execute command
Reply With Quote
  #3 (permalink)  
Old 02-22-2005, 02:05 PM
Junior Member
User
 
Join Date: Feb 2005
Posts: 8
Rep Power: 0
ryan
Send a message via MSN to ryan
Default

right, it achieved what I want.


Quote:
Originally Posted by vivek
I think you need something as follows:

Code:
debug="0" # 0 - true, nonzero = false
str1='ls'
str2='-l'
str3="$str1 $str2" #notice the formular
[ "$debug" == "0" ] && echo "$str1 $str2 $str3" || $str3
if debug is zero then display the values of all three variables str1,str2,str3 else execute command
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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

Similar Threads

Thread Thread Starter Forum Replies Last Post
Not able to connect using remote desktop aliment CentOS / RHEL / Fedora 0 04-14-2008 01:42 PM
fedora 7 connect dsl-502T anthony pereira Getting started tutorials 4 12-22-2007 03:10 PM
split files by specifying a string (bash shell) vikas027 Shell scripting 4 11-01-2007 05:22 PM
Connect mysql in c raj Databases servers 1 08-10-2007 09:10 PM
linux command search server for string chimu Linux software 2 07-26-2006 01:40 AM


All times are GMT +5.5. The time now is 08:25 PM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36