- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- script to add variable in one line
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-04-2011 06:48 AM
тАО03-04-2011 06:48 AM
I have script with the following:
CL="ABC:BCD:CDE"
ID=1
IFS=:
for i in $CL
do
CL_GRP="${CL_GRP} $i $ID"
done
echo CL_GRP
The output should be
'ABC' 1 'BCD' 1 'CDE' 1
but the problem is how can I have the ' sign and the method above seems to always generate one empty space.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-04-2011 07:32 AM
тАО03-04-2011 07:32 AM
SolutionDo you mean?: echo $CL_GRP
> [...] the method above seems to always
> generate one empty space.
Are you complaining about the space at the
beginning of CL_GRP? If so, then, as usual,
many things are possible. For example, one
could use "sed" to remove a leading space:
echo $CL_GRP | sed -e 's/^ //'
Or, one could avoid putting the space in at
the beginning:
first=''
for i in $CL
do
if [ -z $first ]; then
CL_GRP="$i $ID"
first='no'
else
CL_GRP="${CL_GRP} $i $ID"
fi
done
Or (saving a variable):
CL_GRP=''
for i in $CL
do
if [ -z $CL_GRP ]; then
CL_GRP="$i $ID"
else
CL_GRP="${CL_GRP} $i $ID"
fi
done
(So, people don't learn basic computer
programming nowadays?)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-04-2011 07:59 AM
тАО03-04-2011 07:59 AM
Re: script to add variable in one line
for example 'ABC' 'BCD' 'CDE'
instead of ABC BCD CDE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-04-2011 08:04 AM
тАО03-04-2011 08:04 AM
Re: script to add variable in one line
What did you try?
CL_GRP="'$i' $ID"
(and so on)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-04-2011 08:11 AM
тАО03-04-2011 08:11 AM
Re: script to add variable in one line
CL="${'CL'} $i"
but it doesn't return as 'ABC''BCD' 'CDE'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-04-2011 08:23 AM
тАО03-04-2011 08:23 AM
Re: script to add variable in one line
>
> CL="${'CL'} $i"
>
> but it doesn't return as 'ABC''BCD' 'CDE'
Yeah. I can see why. Can you? Did you try
what I suggested?
${'CL'}
Really? Where do you want the ' characters?
Around the old stuff (CL) or around the new
stuff (i)?
Inside the braces? ${CL} makes sense to me.
'${CL}' makes sense to me. ${'CL'} makes no
sense to me. (Or to the shell?)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-06-2011 07:58 AM
тАО06-06-2011 07:58 AM
Re: script to add variable in one line
${VARIABLE%% } to trim trailing spaces.
So your script would become:
for i in $CL
do
CL_GRP="${CL_GRP%% } $i $ID"
done
echo "CL_GRP=\"${CL_GRP}\""