Substring a returned function value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Substring a returned function value
# 1  
Old 06-11-2012
Substring a returned function value

Hello,
I have something that should be very simple yet I am losing my head in figuring out how to get it to work:
I am calling a function passing a parameter, this will return a particular string, next I want to substring the returned value and break it apart.
All of this I want to do on a single line of code under ksh93.

I tried a few combinations but I cannot get it to work. Any ideas?
I suppose I am doing something improper with the brackets and/or parentheses. Here is my one liner:

Code:
new_var=${$(functionCall parametersForFunction):0:4}

I would have expected the chunk:

Code:
$(functionCall parametersForFunction)

to be the returned string from the function call executed, and include it in the substring statement, but no luck, I keep getting a parsing error.

Hope you can help, thanks
# 2  
Old 06-11-2012
Quote:
I am calling a function passing a parameter
Please post the code, the command line typed complete with the exact parameter, the expected output, and what actually happened - complete with any error messages verbatim.
# 3  
Old 06-11-2012
${xxx:y:z} expects xxx to be a variable name but $(functionCall ...) is not.

This will work:
Code:
new_var=$(tmp=$(functionCall parametersForFunction); echo ${tmp:0:4})

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Substring Function

I have a file in which there are other file path and names /home/data/abc.txt /home/data/sdf.txt /home/data/sdg.txt how can I get the file names i.e. abc.txt sdf.txt sdg.txt I searched the forum for sed command but it was confusing to me (10 Replies)
Discussion started by: eskay
10 Replies

2. UNIX for Dummies Questions & Answers

What is returned when using 'find . -ls'

Hi all, I tried to find the reply using google, yet did not find a conclusive answer. When I use 'find . -ls', I get something like: 3423297 8 -rw-r--r-- 1 useradmin staff 135 4 apr 09:46 ./.~lock.dir-file-list.csv# I know that 3423297 is the inode -rw-r--r-- ... (2 Replies)
Discussion started by: dakke
2 Replies

3. Linux

Selecting substring (like SQL Server function)

Hey, geniuses of the world (no--facetious is NOT the word of the day;))! I was wondering if there's a way to extract a specific portion from a string of characters in UNIX/LINUX. Give me the generic capabilities (assuming they exist) and I'll figure out the small details. But if you know... (8 Replies)
Discussion started by: ProGrammar
8 Replies

4. Shell Programming and Scripting

How to do String manipulations using Substring function in Shell

Hi, I have a scenario to just plug out the file name from the following location path. /opt/project/data/int/holdFiles/csv195687.csv So, how do I get just file name which is "csv195687.csv" from the above line using awk/shell scripting? Can we use indexOf and Substring in awk to get... (7 Replies)
Discussion started by: anilvvnn
7 Replies

5. HP-UX

about the value returned from oracle

Hi all can i use unix variable holds the data returned by oracle in a shell script? x=sqlplus -s u/p@h <<! >>fg.log whenever sqlerr exit 1 select count(*) from schema.mat_view; exit ! echo $x Will the $x return the value of count(*)? thanks megh (1 Reply)
Discussion started by: megh
1 Replies

6. HP-UX

ridst returned

The rdist command script is called in the program to synchronize the updated files, I wonder whether the rdist returned can be fetched or not from the program? (0 Replies)
Discussion started by: Frank2004
0 Replies

7. Shell Programming and Scripting

Substring Function

Just so you know guys, I am a SAP Person and I am very new to UNIX. I need a help on a one line code. In one of our script we are referring to a variable ($PN) which has the value /interfaces/DA1/DEV291/outbound/INVOIC which is being used in ftp command. I am just looking for a command to... (1 Reply)
Discussion started by: sasikumar_l
1 Replies

8. Shell Programming and Scripting

Assign the returned value of a function to a variable

Hi, Can anyone please show me how to assign the returned value of a function to a variable? Thanks. (2 Replies)
Discussion started by: trivektor
2 Replies

9. UNIX for Dummies Questions & Answers

Substring function in UNIX shell script

Hi All, Following is the output of a find commnd to locate log directories for various projects of UNIX AIX box: /home/hbinz6pf/projectlibs/dpr_pfsdw_dev/&PH& /opt/tools/ds/Template/&PH& /data/ds/ms/hmsdw/projectlibs/dpr_ms_dev/&PH& /data/ds/riskmi/projectlibs/dpr_riskmi_dev/&PH&... (5 Replies)
Discussion started by: csrazdan
5 Replies

10. Shell Programming and Scripting

Substring function in UNIX shell script

Hi All, Following is the output of a find commnd to locate log directories for various projects of UNIX AIX box: /home/hbinz6pf/projectlibs/dpr_pfsdw_dev/&PH& /opt/tools/ds/Template/&PH& /data/ds/ms/hmsdw/projectlibs/dpr_ms_dev/&PH& /data/ds/riskmi/projectlibs/dpr_riskmi_dev/&PH&... (1 Reply)
Discussion started by: csrazdan
1 Replies
Login or Register to Ask a Question