declaring a variabale as string type


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting declaring a variabale as string type
# 1  
Old 01-22-2011
declaring a variabale as string type

I know that directly we can assign a string to a variable but is there any other way to declare a variable as string type. I am using tcsh shell where I am using a function which would return a value of string type but when I am using return keyword , it is returning only integer value.pls help.
# 2  
Old 01-22-2011
Hi.

Functions only "return" integers ("return codes") (and those are only represented in 8-bits). And return is not a variable.

Variables aren't "typed". They all contain strings. You can notionally alter this behaviour using typeset, but that would only affect what you could assign to that variable, or how it is represented.

It's common to assign the "return string" to a variable within the function before the function terminates.

I never use C-shell. so please post the "function" so we can have a look Smilie
# 3  
Old 01-24-2011
suppose my function name is func1
func1()
{
x="maitree"
return $x
}
y=func1
# 4  
Old 01-24-2011
If you want to get the string as a return type mostly you can use as like..
Code:
func1()
{
x="Hello"
echo "$x"
}
y=`func1`
echo $y

Here no need to return the string Smilie
SmilieBelieve some better way u could find out..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Count occurrence of string (based on type) in a column using awk

Hello, I have a table that looks like what is shown below: AA BB CC XY PQ RS AA BB CC XY RS I would like the total counts depending on the set they belong to: if search pattern is in {AA, BB, CC} --> count them as Type1 | wc -l (3 Replies)
Discussion started by: Gussifinknottle
3 Replies

2. Shell Programming and Scripting

sed - String substitution within specified section in ini type file

Hello. I am trying to modify a config file which is in windows *.ini type file. I have found a piece of code here :linux - Edit file in unix using SED - Stack Overflow As I can't make it doing the job , I am trying to find a solution step by step. here a modified sample file : my_sample.ini... (1 Reply)
Discussion started by: jcdole
1 Replies

3. Shell Programming and Scripting

Output of a Grep(Which already has a variable) into a Variabale

Hi All, I have a an array, in which i need to loop through all the variable and check each variable individually for a pattern. For ex #!/bin/ksh set -A FileNames $(</Temp/AllNames) echo "Total array elements :" ${#FileNames } for i in ${FileNames} do # if the "${i} | grep Last"... (3 Replies)
Discussion started by: baranisachin
3 Replies

4. Shell Programming and Scripting

Declaring arrays in csh

Does anyone know how to declare an array in csh? I don't want to declare any elements in the array because I have a variable that represents the size of the array. For example: the array I want to declare is called sortList and it passes in the variable ARRAYSIZE that stores the value 8. (1 Reply)
Discussion started by: demet8
1 Replies

5. UNIX for Dummies Questions & Answers

PERL: Declaring Array

Is it possible to declare an array in the following way: @tmp = (@f,"String1","String2", "String3",@f); I'm getting the following error message: Array found where operator expected at Program.pl line 181, near "" (Missing semicolon on previous line?) ---------- Post updated at... (1 Reply)
Discussion started by: WongSifu
1 Replies

6. Shell Programming and Scripting

ENV Variabale changes are not retained

ENV varibles set using a script are not retailed once the script execution is done. But if the same ENV variable is set in command line, it is retained. Consider the below case $ cat ti export MDS_CODE_HOME=`pwd` echo $MDS_CODE_HOME rsamadde@pcasvs04 ~/R2ANew $ ti... (3 Replies)
Discussion started by: gogol
3 Replies

7. Programming

Declaring variables

Hey guys im facing a problem in declaring variables. i have a few classes like the one below... #ifndef _FINANCE_H #define _FINANCE_H #include <string> #include <iostream> #include <fstream> #include <stdlib.h> using namespace std ; class readStraitsTimesIndex { ... (3 Replies)
Discussion started by: gregarion
3 Replies

8. Shell Programming and Scripting

declaring variable with for $(seq)

Hi guys. i have the following script: 1 #!/bin/bash 2 linkcount=$(grep "/portal" tickets | wc -l) 3 grep "/portal" tickets > links 4 for i in $(seq 1 $linkcount); do 5 echo "BLYAT" 6 let link$i=$(sed -n "$i"p links) 7 echo $ 8 done the problem is, that "let" can`t... (1 Reply)
Discussion started by: neverhood
1 Replies

9. Shell Programming and Scripting

String type to date type

Can one string type variable changed into the date type variable. (1 Reply)
Discussion started by: rinku
1 Replies

10. Shell Programming and Scripting

Declaring Local Arrays

I have some function function() { fileNamelist=( `find Uploads -name "somePattern" | tr '\n' ' '` ) } but "local fileNamelist" makes it variable. How do I declare fileNameList as a local array in BASH? (1 Reply)
Discussion started by: ksh
1 Replies
Login or Register to Ask a Question