Array with special Characters


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Array with special Characters
# 1  
Old 06-06-2008
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  
Old 06-08-2008
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

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to escape all special characters?

I have an application which I am integrating with that accepts the password via a CLI. I am running in to issues with passwords that contain special characters. I tried to escape them all, but I ran in to an issue where I cannot escape the characters ' ] My attempt is as follows: $... (2 Replies)
Discussion started by: AMG1978
2 Replies

2. Shell Programming and Scripting

Need help in replacing special characters

I am writing a ksh script. I need to replace a set of characters in an xml file. FROM="ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÛÚÜÝßàáâãäåçèéêëìíîïðñòóôõö¿¶ø®"; TO="AAAAAAACEEEEIIIIDNOOOOOOUUUUYSaaaaaaceeeeiiiionooooo N R" I have used the code- sed 's/$FROM/$TO/g'<abc.xml But its not working. Can anyone tell me the code to do this? (3 Replies)
Discussion started by: saga20
3 Replies

3. Shell Programming and Scripting

Replace special characters with Escape characters?

i need to replace the any special characters with escape characters like below. test!=123-> test\!\=123 !@#$%^&*()-= to be replaced by \!\@\#\$\%\^\&\*\(\)\-\= (8 Replies)
Discussion started by: laknar
8 Replies

4. Shell Programming and Scripting

special characters

Hey guys, I'm trying to replace "]Facebook" from the text but sed 's/]Facebook/Johan/g' is not working could you please help me with that? (6 Replies)
Discussion started by: Johanni
6 Replies

5. UNIX for Dummies Questions & Answers

How to see special characters?

Hi all, I was wondering how can i see the special characters like \t, \n or anything else in a file by using Nano or any other linux command like less, more etc (6 Replies)
Discussion started by: gvj
6 Replies

6. Shell Programming and Scripting

Special characters

When I open a file in vi, I see the following characters: \302\240 Can someone explain what these characters mean. Is it ASCII format? I need to trim those characters from a file. I am doing the following: tr -d '\302\240' ---------- Post updated at 08:35 PM ---------- Previous... (1 Reply)
Discussion started by: sid1982
1 Replies

7. Shell Programming and Scripting

@ is a special array

Hi all, I've got this silly problem:var="foo bar baz"; echo "${var% *}"; myEcho() { echo "\"${@::${#@}}\"" -- ${@: -1}; }; myEcho foo bar baz foo bar "foo bar" -- bazthat is OK, butset -x;manSearch() { man -LC -P"less -p \"${@::${#*}}\" ${*: -1}"; }; manSearch Parameter Expansion bashtells:+... (0 Replies)
Discussion started by: daPeach
0 Replies

8. Shell Programming and Scripting

create array holding characters from sring then echo array.

Hi, I wish to store $string1 in $string1array a character in each array element. Then i wish to echo the entire array to the screen so that it reads as the normal string again. I have been trying with the code below but does not work. Please help... To put string into array: ... (5 Replies)
Discussion started by: rorey_breaker
5 Replies

9. UNIX for Dummies Questions & Answers

Special Characters in directory name

Hi all, I've got a couple of directorys with special chars in the name: # ls -q personnel?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D?[D unilive_?[B?[H?[L?[F?[L?[L?[Lpwd I do not know how to get into these... (6 Replies)
Discussion started by: tez
6 Replies

10. UNIX for Dummies Questions & Answers

special characters

I have one file which is named ^? ( the DEL character ) I'd like to know how to rename or copy the file by using its i-node number TYIA (2 Replies)
Discussion started by: nawnaw
2 Replies
Login or Register to Ask a Question