0

I am using this shell script

#!/bin/sh

file_name="'STG_MAP_RM_ARN'"

var_log_tbl_date="'29-MAR-2016'"

var_err_file_list=$($ORACLE_HOME/bin/sqlplus -s obi_user/obi_user@UNNATIDEV
<<
END

set pagesize 0 feedback off verify off heading off echo off;

SELECT WM_CONCAT(A) FROM (SELECT DISTINCT COL15 AS A FROM ERROR_TABLE WHERE FILENAME=${file_name} AND FILEDATE=${var_log_tbl_date});

exit;

END
)

echo $var_err_file_list

If I am executing the command in sql, the output is:

20160727_RM_ARN_MAPPING.csv,YYYYMMDD_RM_ARN_MAPPING.csv,20160728_RM_ARN_MAPPING.csv

But the shell script output is:

20160727_RM_ARN_MAPPING.csv,YYYYMMDD_RM_ARN_MAPPING.csv,20160728_RM_ARN_MAPPING.

The shell output is getting truncated as you can see (.csv is missing in o/p)

Is there any limitation for variable sizes in Unix?

Please help me

codersl
  • 2,222
  • 4
  • 30
  • 33
  • Here, the Unix variable var_err_file_list is taking maximum length of only 80 characters. – Pavani Srujana Sep 15 '16 at 10:55
  • Is there a reason you are storing big values in a shell variable? There may be alternative solutions for your problem (than use a variable). What are you trying to do (after storing the big value in a shell variable)? – blackpen Sep 15 '16 at 11:02
  • @blackpen,As you can see,I will get a comma separated result, And later I need to loop through all those values and have some unix operations. Also I need to send this variable in a mail from unix.So it is mandatory for me to take into a variable. – Pavani Srujana Sep 15 '16 at 11:04
  • Fix the hashbang line to start with "#!", or you won't know which shell will execute this code. Hint: Try with different shells, e.g., `/bin/sh /path/to/script` or dash, bash, ksh – Henk Langeveld Sep 15 '16 at 11:13
  • @Langeveld. Sorry it has "#!" .It is just a copy paste issue – Pavani Srujana Sep 15 '16 at 11:29

2 Answers2

1

There are few alternatives:

1) You can use the mktemp command to create a temporary file, redirect your contents to that file, reuse the contents as many times as you want, then remove the file.

    mktemp mytemp_file_XXXXXXXXX.log

2) Thre are alternatives like mk_fifo in combination with tee command that let you duplicate the output and channel it into multiple commands. If your shell let's you (ksh93, zsh, bash), you can also arrange for duplicated outputs like the following:

    # Writes stdout into both
    cat main.c > 1.txt > 2.txt

    #Duplicates output to two cat commands; also writes it to console
    cat main.c | tee >( cat>1.txt) >(cat>2.txt)

To use these features you need bash, zsh or ksh93.

Refer to this relevant post

Community
  • 1
  • 1
blackpen
  • 2,339
  • 13
  • 15
-1

There does not seem to be a per Variable limitation but an overall limitation for all Variables together. See: What is the maximum size of an environment variable value?

Community
  • 1
  • 1
Alexander B.
  • 120
  • 1
  • 9