Sponsored Content
Top Forums Shell Programming and Scripting Problem to initialize ksh array when first element includes hyphen Post 302539987 by Scott on Tuesday 19th of July 2011 09:28:57 AM
Old 07-19-2011
Because "allArgs" is empty.first time, it's treating "-all" as an argument to "set".

If you have some values in allArgs before appending itself then -add, the problem goes away.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

accessing my first element of array

Hello everyonel, I have an array set like so num=4 read name arr=name I go through while loop to assign different values to different array element from 1 to 4. when I try to access the FIRST element of the array I get the last one first. Like if I say ${arr} it will show the last element... (4 Replies)
Discussion started by: afadaghi
4 Replies

2. Shell Programming and Scripting

Adding array element in KSH

All, I would like to add the first 10 elements of an array. Here is how I am doing it now (only included first few add ops): #!/usr/bin/ksh ###Grab the array values out of a file### TOTAL=`awk '/time/' /tmp/file.out | awk '{print $4}'` set -A times $TOTAL SUM=$((${times} + times... (3 Replies)
Discussion started by: Shoeless_Mike
3 Replies

3. Shell Programming and Scripting

How to initialize array with a larger number?

Language: ksh OS: SunOS I have been getting the 'subscript out of range' error when the below array variable gets elements greater that 1024. I understand that 1024 is the default size for 'set -A' dynamic array, but is there a way to initialize it with a larger number? set -A arr `grep... (6 Replies)
Discussion started by: ChicagoBlues
6 Replies

4. Shell Programming and Scripting

ksh function getopts get leading underscore unless preceded by hyphen

If I call my function with grouped options: "logm -TDIWEFO 'message' ", then only the "T" gets parsed correctly. The subsequent values returned have underscores prefixed to the value: "_D", "_I", etc. If I "logm -T -DIWEFO 'message' ", the "T" and the "D" are OK, but "I" through "O" get the... (2 Replies)
Discussion started by: kchriste
2 Replies

5. Shell Programming and Scripting

remove an element from array

I need to remove an element from the below array variable TABLENAME. #!/bin/ksh set -A TABLENAME "mirf roxar keke mirs" echo "the array is ${TABLENAME}" If i need to remove say keke and have the final TABLENAME as below, how this could be achieved. Pls throw some light. echo "Modified... (3 Replies)
Discussion started by: michaelrozar17
3 Replies

6. Emergency UNIX and Linux Support

Assigning zero to element of ksh array.

set -A matched #find referenced files. for i in ${file_names_html} do counter_j=0 for j in ${file_names_minus_index} do match=`cat $i | grep... (1 Reply)
Discussion started by: robin_simple
1 Replies

7. Shell Programming and Scripting

ksh insert element in array

Hi all, I need help with the following scenario in ksh. If the number of elements contained by arrayA is 11 I need to insert a zero as the element arrayA then print all arrayA elements separated by comma. Appreciate your help. (9 Replies)
Discussion started by: ejianu
9 Replies

8. Shell Programming and Scripting

Not able to call an element from an array in ksh

Hi, I have: # Initialize variables #!/usr/bin/ksh FILENM=$1 INDEX=0 # read filename echo "You are working with the Config file: $FILENM" while read line do echo $line data=$line ((INDEX=INDEX+1)) done <"$FILENM" (3 Replies)
Discussion started by: Marc G
3 Replies

9. Shell Programming and Scripting

File names as array element in ksh

Hi, I have an ksh array(ARR). the elements to the array are file names. i need to go to each file in the array and manipulate the records. for name in ${files}; do ---this loop is for all the file names in the array for i in $(wc -l < $name); do --this loop is for all the records in... (20 Replies)
Discussion started by: usrrenny
20 Replies

10. UNIX for Advanced & Expert Users

Array Element

This question is for someone that's more familiar with Array Element. I need to know if the maximum array element that can be assigned is 1024 and if its so, Is there a workaround solution when the counter exceeded 1024? param_array="$param_nam" counter=$counter+1 #to avoid space... (3 Replies)
Discussion started by: cumeh1624
3 Replies
Tcl_DString(3)						      Tcl Library Procedures						    Tcl_DString(3)

__________________________________________________________________________________________________________________________________________________

NAME
Tcl_DStringInit, Tcl_DStringAppend, Tcl_DStringAppendElement, Tcl_DStringStartSublist, Tcl_DStringEndSublist, Tcl_DStringLength, Tcl_DStringValue, Tcl_DStringSetLength, Tcl_DStringTrunc, Tcl_DStringFree, Tcl_DStringResult, Tcl_DStringGetResult - manipulate dynamic strings SYNOPSIS
#include <tcl.h> Tcl_DStringInit(dsPtr) char * Tcl_DStringAppend(dsPtr, string, length) char * Tcl_DStringAppendElement(dsPtr, string) Tcl_DStringStartSublist(dsPtr) Tcl_DStringEndSublist(dsPtr) int Tcl_DStringLength(dsPtr) char * Tcl_DStringValue(dsPtr) Tcl_DStringSetLength(dsPtr, newLength) Tcl_DStringTrunc(dsPtr, newLength) Tcl_DStringFree(dsPtr) Tcl_DStringResult(interp, dsPtr) Tcl_DStringGetResult(interp, dsPtr) ARGUMENTS
Tcl_DString *dsPtr (in/out) Pointer to structure that is used to manage a dynamic string. CONST char *string (in) Pointer to characters to add to dynamic string. int length (in) Number of characters from string to add to dynamic string. If -1, add all characters up to null termi- nating character. int newLength (in) New length for dynamic string, not including null terminating character. Tcl_Interp *interp (in/out) Interpreter whose result is to be set from or moved to the dynamic string. _________________________________________________________________ DESCRIPTION
Dynamic strings provide a mechanism for building up arbitrarily long strings by gradually appending information. If the dynamic string is short then there will be no memory allocation overhead; as the string gets larger, additional space will be allocated as needed. Tcl_DStringInit initializes a dynamic string to zero length. The Tcl_DString structure must have been allocated by the caller. No assump- tions are made about the current state of the structure; anything already in it is discarded. If the structure has been used previously, Tcl_DStringFree should be called first to free up any memory allocated for the old string. Tcl_DStringAppend adds new information to a dynamic string, allocating more memory for the string if needed. If length is less than zero then everything in string is appended to the dynamic string; otherwise length specifies the number of bytes to append. Tcl_DStringAppend returns a pointer to the characters of the new string. The string can also be retrieved from the string field of the Tcl_DString struc- ture. Tcl_DStringAppendElement is similar to Tcl_DStringAppend except that it doesn't take a length argument (it appends all of string) and it converts the string to a proper list element before appending. Tcl_DStringAppendElement adds a separator space before the new list element unless the new list element is the first in a list or sub-list (i.e. either the current string is empty, or it contains the single charac- ter ``{'', or the last two characters of the current string are `` {''). Tcl_DStringAppendElement returns a pointer to the characters of the new string. Tcl_DStringStartSublist and Tcl_DStringEndSublist can be used to create nested lists. To append a list element that is itself a sublist, first call Tcl_DStringStartSublist, then call Tcl_DStringAppendElement for each of the elements in the sublist, then call Tcl_DStringEnd- Sublist to end the sublist. Tcl_DStringStartSublist appends a space character if needed, followed by an open brace; Tcl_DStringEndSublist appends a close brace. Lists can be nested to any depth. Tcl_DStringLength is a macro that returns the current length of a dynamic string (not including the terminating null character). Tcl_DStringValue is a macro that returns a pointer to the current contents of a dynamic string. Tcl_DStringSetLength changes the length of a dynamic string. If newLength is less than the string's current length, then the string is truncated. If newLength is greater than the string's current length, then the string will become longer and new space will be allocated for the string if needed. However, Tcl_DStringSetLength will not initialize the new space except to provide a terminating null character; it is up to the caller to fill in the new space. Tcl_DStringSetLength does not free up the string's storage space even if the string is truncated to zero length, so Tcl_DStringFree will still need to be called. Tcl_DStringTrunc changes the length of a dynamic string. This procedure is now deprecated. Tcl_DStringSetLength should be used instead. Tcl_DStringFree should be called when you're finished using the string. It frees up any memory that was allocated for the string and reinitializes the string's value to an empty string. Tcl_DStringResult sets the result of interp to the value of the dynamic string given by dsPtr. It does this by moving a pointer from dsPtr to the interpreter's result. This saves the cost of allocating new memory and copying the string. Tcl_DStringResult also reinitializes the dynamic string to an empty string. Tcl_DStringGetResult does the opposite of Tcl_DStringResult. It sets the value of dsPtr to the result of interp and it clears interp's result. If possible it does this by moving a pointer rather than by copying the string. KEYWORDS
append, dynamic string, free, result Tcl 7.4 Tcl_DString(3)
All times are GMT -4. The time now is 03:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy