nixCraft Linux / UNIX / Shell Scripting Forum

nixCraft

Linux / UNIX 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 ...


Register free or login to your account to remove all advertisements.

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

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

Thread Tools Display Modes
  #1 (permalink)  
Old 22nd February 2005, 11:52 AM
Junior Member
 
Join Date: Feb 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
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
  #2 (permalink)  
Old 22nd February 2005, 12:23 PM
Administrator
 
Join Date: Jan 1970
Posts: 43
Thanks: 0
Thanked 2 Times in 1 Post
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 22nd February 2005, 01:05 PM
Junior Member
 
Join Date: Feb 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
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


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 Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
split files by specifying a string (bash shell) vikas027 Shell scripting 7 21st June 2010 12:35 PM
Not able to connect using remote desktop aliment CentOS / RHEL / Fedora 0 14th April 2008 12:42 PM
fedora 7 connect dsl-502T anthony pereira Getting started tutorials 4 22nd December 2007 02:10 PM
Connect mysql in c raj Databases servers 1 10th August 2007 08:10 PM
linux command search server for string chimu Linux software 2 26th July 2006 12:40 AM


All times are GMT +5.5. The time now is 09:00 PM.


Powered by vBulletin® Version 3.8.6 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

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 37 38 39 40