Sponsored Content
Top Forums Shell Programming and Scripting Using unset to delete array elements Post 302250061 by msb65 on Wednesday 22nd of October 2008 04:21:50 PM
Old 10-22-2008
Using unset to delete array elements

Hi,

I am writing a BASH script. My questions regard deleting elements of arrays.

I have an array:
michael-browns-powerbook-g4-15:~ msb65$ test_array=(1 2 3 4)
michael-browns-powerbook-g4-15:~ msb65$ echo ${test_array[@]}
1 2 3 4

To delete the second element of test_array I type:
michael-browns-powerbook-g4-15:~ msb65$ unset test_array[1]
michael-browns-powerbook-g4-15:~ msb65$ echo ${test_array[@]}
1 3 4

I would like to again delete the second element (which is now 3). So I repeat the previous two lines of code:
michael-browns-powerbook-g4-15:~ msb65$ unset test_array[1]
michael-browns-powerbook-g4-15:~ msb65$ echo ${test_array[@]}
1 3 4

- Why is it that the second element was not deleted? Am I not deleting array elements properly?

Thanks.
Mike
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

PHP: how can I delete empty/NULL elements from a multi-dimensional array.

Hi all I have a file that i'm running and exec(cat ./dat) against..and putting its contents into any array, then doing an exploding the array into a multi-dimension array... The 15 multi-dimensional arrays have elements that are null/empty, I would like to remove/unset these elements and then... (2 Replies)
Discussion started by: zeekblack
2 Replies

2. Shell Programming and Scripting

Array with String Elements

How can I get my array to understand the double-quotes I'm passing into it are to separate text strings and not part of an element? here's what I'm working with... db2 -v connect to foo db2 -x "select '\"' || stats_command || '\",' from db2law1.parallel_runstats where tabname = 'BAZ'" set... (4 Replies)
Discussion started by: djschmitt
4 Replies

3. UNIX for Dummies Questions & Answers

Help with replacing Array elements

Hi, I have an array containing following sample information @array = qw (chr02 chr02 chr02 chr02 chr02 chr03 chr03 chr04 chr04 chr05 chr05 chr05 chr07 chr07) I need to replace all duplicate entries by an underscore to get the following output@array = qw (chr02 _ _ _ _ chr03 _ chr04 _ chr05 _ _... (4 Replies)
Discussion started by: pawannoel
4 Replies

4. UNIX for Dummies Questions & Answers

printing array elements

Is there a way to print multiple array elements without iterating through the array using bash? Can you do something like... echo ${array}and get all those separate elements from the array? (2 Replies)
Discussion started by: jrymer
2 Replies

5. Shell Programming and Scripting

Grouping array elements - possible?

I have a script which takes backup of some configuration files on my server. It does that by using an array which contains the complete path to the files to backup. It copys the files to a pre defined dir. Each "program" has it's own folder, ex. apache.conf is being copied to /predefined... (7 Replies)
Discussion started by: dnn
7 Replies

6. Programming

Array Elements Check

Hi everyone, :) I'm trying to make a simple C program that scans an array of chars to see if its elements are similar. I can't understand what's wrong. Could you help me to fix this? Here is the code. Thanks! #include<stdio.h> int main() { int arr; int i, len; int flag =... (10 Replies)
Discussion started by: IgorGest
10 Replies

7. Shell Programming and Scripting

Random elements from array

Hi I wanted to print random elements from an array at bash shell I use the following code, but I always see first element getting printed #!/bin/bash c=1 expressions=(pink red white yellow purple) while ]; do echo "The value of RANDOM is $RANDOM" selectedexpression=${expressions}]};... (5 Replies)
Discussion started by: Priya Amaresh
5 Replies

8. Shell Programming and Scripting

Help reading the array and sum of the array elements

Hi All, need help with reading the array and sum of the array elements. given an array of integers of size N . You need to print the sum of the elements in the array, keeping in mind that some of those integers may be quite large. Input Format The first line of the input consists of an... (1 Reply)
Discussion started by: nishantrefound
1 Replies

9. UNIX for Beginners Questions & Answers

Unset array element and save to file in Bash

#!/bin/bash X=(2H 4S 10D QC JD 9H 8S) How do I unset the 10D from this array and save it to a file? Please use CODE tags as required by forum rules! (5 Replies)
Discussion started by: cogiz
5 Replies

10. Shell Programming and Scripting

Get unique elements from Array

I have an array code and output is below: echo $1 while read -r fline; do echo "%%%%%%$fline%%%%%" fmy_array+=("$fline") done <<< "$1" Output: CR30903 YU0007 SRIL CR30903 Yogesh SRIL %%%%%%CR30903 YU0007 SRIL%%%%% %%%%%%CR30903 Yogesh SRIL%%%%% ... (8 Replies)
Discussion started by: mohtashims
8 Replies
ME 
TV(1) Me TV Manual ME TV(1) NAME
me-tv - a digital television (DVB) viewer for GNOME SYNOPSIS
me-tv [-?|--help] [-v|--verbose] [-s|--safe-mode] [-m|--minimised] [--disable-epg] [--disable-epg-thread] [--no-screensaver-inhibit] [--devices] [--read-timeout] [--display=DISPLAY] DESCRIPTION
Me TV is a GTK desktop application for watching digital television services that use the DVB standard. Me TV works with DVB-T/C/S and ATSC cards that have kernel driver support. Me TV uses the xine video player to render its output onto its video window. Me TV reads the Electronic Program Guide (EPG) data that is transmitted over the air to populate a built-in program guide which can be used for scheduling recordings. Me TV has a built-in scanner which can autoscan certain countries or use an initial scan file. OPTIONS
-?|--help Show help options. -v|--verbose Show verbose output. -s|--safe-mode Show the preferences dialog an don't show video upon start. -m|--minimised-mode Show minimised in notification area at startup. --disable-epg Stops the rendering of the EPG event buttons on the UI. --disable-epg-thread Disable the EPG thread. Me TV will stop collecting EPG events. --no-screensaver-inhibit Tells Me TV not to call the screensaver Inhibit/UnInhibit methods for GNOME Screensaver. --devices Only use the specified frontend devices. You can specify more than one device by using a comma or colon separator. (e.g. --devices=/dev/dvb/adapter0/frontend1) --read-timeout How long to wait (in seconds) before timing out while waiting for data from demuxer (default 5) --display=DISPLAY X display to use AUTHOR
Michael Lamothe (2007-2011) <michael.lamothe@gmail.com>. COPYRIGHT
Copyright (C) 2011 Michael Lamothe <michael.lamothe@gmail.com>. 1.3.6 2011-01-20 ME TV(1)
All times are GMT -4. The time now is 04:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy