ksh

Total count of the array values

一个人想着一个人 提交于 2019-12-13 08:57:22
问题 Here I'm accepting few mount points from the user and using each value to get space available on the host. ./user_input.ksh -string /m01,/m02,/m03 #!/bin/ksh STR=$2 function showMounts { echo "$STR" arr=($(tr ',' ' ' <<< "$STR")) printf "%s\n" "$(arr[@]}" for x in "${arr[@]}" do free_space=`df -h "$x" | grep -v "Avail" | awk '{print $4}'` echo "$x": free_space "$free_space" done #echo "$total_free_space" } Problems: How can I exit for loop if any of the user input mount not avaialble?

Comparing two text files printing result in new header [closed]

可紊 提交于 2019-12-13 08:24:54
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 4 years ago . Okay i will reupdate this I have 2 files - File1.txt , File2.txt File1 is base template File2 is having status result file1.txt N1,N2,N3,N4,N5,N6 XX,ZZ,XC,EE,RR,BB XC,CF,FG,RG,GH,GH file2.txt DF,GH,MH,FR,FG,GH,NA XX,ZZ,XC,EE,RR,BB,OK Below command compares column 1 in both files if it matches then

ksh + printf , print the line with stat gap

六眼飞鱼酱① 提交于 2019-12-13 06:35:23
问题 I need to print the following: need smart ways by printf to print this example param1 ............... value1 param2 ............... value2 param3 ............... value1 param4 ............... value2 THX 回答1: for i in 1 2 3 4 do printf "param%d ................. value%d\n" $i $i done 回答2: This works in ksh93. I don't know about earlier versions. This will print the data in columns with up to n dots between them n=10 printf "%s %s %s\n" $column1 $( printf '.%.0s' {1..$(($n - ${#column1}))} )

KSH Shell script not zipping up files

南笙酒味 提交于 2019-12-13 04:12:11
问题 I have a Korn shell script that is supposed to zip up files and it is not working properly in development. The same exact script works in production which is strange. We recently upgraded our Solaris Unix box to a Linux box in the development environment. So I am assuming that this may be the cause of the script not executing. The pic below is shows the file list. The user will select a checkbox for the files they want to download and then they click the zip and download link and it should

If file in Unix

帅比萌擦擦* 提交于 2019-12-13 04:02:45
问题 I have a code if ["a1 a2" = "a*"] then echo match else echo "a*" fi that I have typed and the return statement is a* main.ksh[3]: [a1 a2: not found [No such file or directory] I am wondering why this is, I thought the if statement only compared the strings. What does it have to do with files and directories? 回答1: Spacing issue, you need to do if [ "a1 a2" = "a*" ] otherwise at least "a1 will get treated as part of the test operator. Also to do regex matching, you need to do something like if

Does the shell support sets?

杀马特。学长 韩版系。学妹 提交于 2019-12-13 00:36:03
问题 Do shells such as bash and ksh support set operations (such as 'union of two sets')? I can't find any tutorial about this using Google. 回答1: What about this set-operations-in-unix-shell. 回答2: As far as I know, POSIX shell (including bash) doesn't support sets operation. But you can build your own, for example, by making use of bash associative array (bash 4.0 and later). 回答3: No bash/ksh doesn't support dedicated sets operations. You will have to program your own if you insists on using the

Idiomatic way to exit ksh while loop

假装没事ソ 提交于 2019-12-13 00:14:51
问题 I've the following 5 second timer which prints an asterisk for each second. timer () { i=1 trap 'i=5' INT while [[ $i -le 5 ]]; do sleep 1 printf "*" ((i+=1)) done } Somehow the trap chunk seems a little hackish and I wonder if there's a more correct way to interrupt the entire loop (not just the current sleep cycle). I've tried: trap 'print "foo"' INT at various locations inside and outside the function, but as I alluded to before, that just interrupts the current sleep cycle. 回答1: Perhaps I

getting syntax error at line 34 : `<<' unmatched in ksh script

社会主义新天地 提交于 2019-12-12 20:25:16
问题 I have a shell script, when I execute it, I get the error syntax error at line 34 : `<<' unmatched in ksh script column_name=`sqlplus -s $BASE_DB_CONN<<!! WHENEVER SQLERROR exit ROLLBACK set SQLPROMPT '' set heading off set pagesize 1000 set linesize 5000 set feedback off set define on set verify off @smm9_stream_map.sql $STREAM_NAME $FIELD_NAME" exit !!`; To my surprise the same thing works in the while loop altered script as below while [ $a -lt ${NO_LOOP} ] do column_name=`sqlplus -s $BASE

getting last executed command from script

情到浓时终转凉″ 提交于 2019-12-12 18:59:53
问题 I'm trying to get last executed command from command line from a script to be saved for a later reference: Example: # echo "Hello World!!!" > Hello World!!! # my_script.sh > echo "Hello World!!!" and the content of the script would be : #!/usr/bin/ksh fc -nl -1 | sed -n 1p Now as you notices using here ksh and fc is a built in command which if understood correctly should be implemented by any POSIX compatible shells. [I understand that this feature is interactive and that calling same fc

How to delete all lines except lines that include TRUNCATE - INSERT

只谈情不闲聊 提交于 2019-12-12 18:28:24
问题 I have created a script that formats all of my PL/SQL files into a simple file that has pairs of values, its quite hard to explain, i think it will be easier if you just look at the file; PROCEDURE VALIDA_CAMBIO_GPR TRUNCATE TMP_MOD_PVA INSERT TMP_MOD_PVA PROCEDURE AJUSTAR_FECHAS INSERT PRO_TDA_VARLOG_ALM PROCEDURE DEPURAR_CAMBIOS_GPR PROCEDURE INC_EX_0001 INSERT CABECERA_ALARMAS PROCEDURE INC_EX_0002 INSERT CABECERA_ALARMAS PROCEDURE INC_EX_0003 INSERT CABECERA_ALARMAS PROCEDURE INC_EX_0005