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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
unescaping special characters sriram_r Shell Programming and Scripting 3 02-06-2008 07:59 AM
Handling special characters using awk sam_78_nyc Shell Programming and Scripting 3 11-08-2007 05:55 PM
create array holding characters from sring then echo array. rorey_breaker Shell Programming and Scripting 5 09-28-2007 08:42 AM
special characters nawnaw UNIX for Dummies Questions & Answers 2 05-18-2004 03:17 PM
awk/sed with special characters apalex Shell Programming and Scripting 5 05-06-2002 04:40 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-06-2008
donaldfung donaldfung is offline
Registered User
  
 

Join Date: Feb 2005
Posts: 7
Array with special Characters

Hi,

I would write a shell script to execute a series of command. However, if the cmd contains "-" in the array. It fails to do so.

I'd tried use ', " or \ but get the same result.

Quote:
#!/bin/bash

function checkConfig ()
{
for process in ${diskInfo[@]}
do
eval "${process}"
done
}

# Disk info details to be tar into tape
diskInfo=( 'df -k' "/sbin/fdisk -l" "cat /etc/fstab" )

checkConfig

Output:
Quote:
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 51605464 6134364 42849696 13% /
/dev/sda1 101086 17977 77890 19% /boot
none 2072328 0 2072328 0% /dev/shm
/dev/sda5 807659692 144174644 622458256 19% /u01
./test.sh: line 31: -k: command not found

Usage: fdisk [-l] [-b SSZ] [-u] device
E.g.: fdisk /dev/hda (for the first IDE disk)
or: fdisk /dev/sdc (for the third SCSI disk)
or: fdisk /dev/eda (for the first PS/2 ESDI drive)
or: fdisk /dev/rd/c0d0 or: fdisk /dev/ida/c0d0 (for RAID devices)
...
./test.sh: line 31: -l: command not found
  #2 (permalink)  
Old 06-08-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,912
The following code snippet will show you how to extract the array contents
Code:
#!/usr/bin/bash

diskInfo=( 'df -k' "/sbin/fdisk -l" "cat /etc/fstab" )
num=${#diskInfo[@]}             # returns 3

for ((i = 0; i < $num; i++))
do
   echo ${diskInfo[$i]}
done
Sponsored Links
Closed Thread

Bookmarks

Tags
bash, bash eval, eval

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 08:07 PM.


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