The Korn shell (ksh) is a shell with advanced scripting features, commonly found on commercial unices and some BSD systems but rarely used on Linux.

learn more… | top users | synonyms

2
votes
2answers
189 views

Meaning of \ before environment variable

In ksh on an old Solaris box I used: export PS1="$PWD $" to set the prompt to the current directory. It works great until you cd elsewhere, then you see that it's not evaluating PWD each time. I ...
2
votes
1answer
32 views

set -xv behavior in ksh vs bash

Normally I like to have all of the debug output of a script go to a file, so I will have something like: exec 2> somefile set -xv This work very will in bash, but I have noticed in ksh it ...
0
votes
1answer
41 views

Null message body; hope that's ok

I have the following command below as part of a cronjob. When I run the command via cron or at the command line, I get Null message body; hope that's ok. The contents of the email are empty but when ...
0
votes
0answers
27 views

How to run multiple queries in a KSH script

I have a KSH script that has one SQL Query and generates and emails output of the query in HTML format. I want to change the script so that it has three SQL queries and the last query generates and ...
1
vote
3answers
59 views

I want to divide a sum of numbers by a value

So here is my code for Unix shell scripting #! /bin/ksh echo "Enter your first number:" read first echo "Enter your second number:" read second echo "Enter your third number:" read ...
1
vote
2answers
52 views

Passing print pattern as a variable to awk

I am trying to use awk to print variables from various columns in a line delimited by , .The columns and pattern which I want to print is stored in another variable b. The pattern a and print patter ...
1
vote
3answers
168 views

How to get a response from any URL?

I have been asked to write a shell script To check if a URL is UP/Working or not for my Project. I tried to find some hints over the internet, but whatever I got is about checking whether the URL ...
3
votes
2answers
83 views

Is there a way to prevent a non-terminal-attached process from executing 'who' inside my .envfile?

I made some modifications to the /home/user/.envfile so the PS1 prompt would show date/time as well as the pwd etc. The modification is: # `who am i` is used to obtain the name of the original user ...
1
vote
3answers
43 views

Using a command's output in printf in ksh

I am trying to perform the following : printf "Are you sure you want to copy %s (y/n) ? (file bigger than 10 MB) " "$0" It works fine, nevertheless, I would like to display the actual size of my ...
1
vote
1answer
43 views

why is EXPORT PS1 in my .profile getting clobbered?

In this question How can I get KornShell to display the date and time in the prompt? all the variables are visible in ksh except PS1 which appears to be getting replaced somehow. How can I determine ...
0
votes
1answer
314 views

Copy a file from a remote server to windows home using scp

Is there a way to copy a file from a server to a local folder (i.e. My Documents)? can it be done by scp? I have this script that generate some list. I want this script to automatically copy the ...
2
votes
3answers
254 views

Run a script on multiple shells?

I have two servers one AIX with default shell ksh, the other RHEL with default shell bash. I have a script that is mounted on both that will run similar commands but for either AIX or Linux. This ...
2
votes
1answer
71 views

How can I get KornShell to display the date and time in the prompt?

On my AIX box, which is using ksh as the default shell, I'd like the prompt to show both the date and time followed by a newline \n, along with the name of the machine, and the working directory. ...
0
votes
0answers
44 views

How to capture INFORMIX DB errors in shell script?

I need to capture the informix DB errors like Update failed, Insert failed using the shell script. I am using ksh shell.
0
votes
1answer
110 views

Why does this command not work on AIX?

I want to remove UTF-8 BOM from a file using this command: sed '1 s/\xEF\xBB\xBF//' old.java > tmp.java But it did not work. I am running with ksh on AIX 7.1
5
votes
1answer
265 views

What is #@(#) in Kornshell syntax

I'm looking at a script on an AIX box where several lines begin with #@(#) What does that indicate? Clearly doing a Google search is totally fruitless for symbols. Here are the lines from the ...
0
votes
1answer
72 views

how do I recursivley grep (or otherwise search for) hex strings

Long and short I'm trying to track down some files left by evil scum on a server. fgrep -r "STRING" /path/here has been working well for finding general stuff. However, how do I search for hex ...
3
votes
1answer
134 views

How do I use sudo to run multiple commands as another user within a portion of a script?

I'm trying to run the following: if [! -f .owner ]; then creator=$(whoami) sudo -u appuser ksh echo "$creator" >> .owner mkdir test1 test2 test3 exit fi However, the ...
1
vote
2answers
266 views

How to check a ksh script for syntax errors?

$ cat foo.sh #!/bin/ksh echo foo ehco foo2 It doesn't warns for errors: $ /bin/ksh -n foo.sh $ echo $? 0 Question: How can I get the "ksh -n" to warn me about syntax errors?
0
votes
1answer
211 views

aix ksh start weblogic server without nohup.out and return to underlying script

I am writing a ksh script, in which I want to start weblogic server in background and return to underlying script immediately(continue to execute the script) like this: nohup ...
5
votes
2answers
260 views

how to return to underlying script from tail -f

I have a ksh script, in which I use tail -f to view a log file. How can I terminate the tail process, and continue executing the underlying script? I am running it on AIX 7.1. ...
2
votes
3answers
361 views

Shell script not executing

Not sure what is happening. Lets call script a.sh with the following /users/guru$ cat a.sh #! /usr/bin/ksh echo "Hello" date Execute with ksh. It gets done. /users/guru$ ksh a.sh Hello Tue Jul ...
1
vote
3answers
107 views

Problem when splitting command with backslash in unix prompt

I often use the space-backslash combination ( ) to split a command and its parameters into various lines and make it more readable: /home/user> ls -ltra \ > file1.txt \ > file2.txt ...
1
vote
2answers
40 views

what's the right pattern to match my command

OS: AIX 7.1 I am working on a shell script which let user input some command and execute it, one of the commands is in this form: compile appname the appname only can be one of [ccms|asws], what's ...
3
votes
1answer
159 views

how to get exit status from command in expect script

Below is an shell script I have written to automate entering the password for the vpnc command. The expect works fine and vpnc activated automatically after password entered, but I need to get the ...
1
vote
3answers
93 views

Sed + how to set parameters in sed command in order to display lines from text file

I find the following way to print line from file In this example we want to print the first line from the hosts file sed -n '1,1p' /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 ...
0
votes
1answer
122 views

Error unzipping file through ksh, unzip works through bash

I have an auto-generated zipfile foo.zip on a Red Hat server that needs to be extracted to a particular location /bar. This is done through an install script using ksh. When the script executes unzip ...
1
vote
2answers
331 views

Aix grep wildcard not working

I have a file called message that has the line CSC/UT/USA/WBIMB/SAP/orders05:orders05/ORDERS05/NONE/ORDRSP/758 I am doing a grep (Platform is AIX 6.1) grep ...
1
vote
2answers
113 views

How to convert text or character to hex in korn shell

Does the unix korn shell provide a function to convert text or character to hex eg. hex 31 32 37 33 34 35 35 36 36 37 value of characters 1273455667 Here i have written the code to display but i don't ...
3
votes
5answers
134 views

Get values block by block in same file

I have a file say "SAMPLE.txt" with following content, P1 10,9:6/123456 P2 blah blah P1 10,9:5/98765 P2 blah blah P1 blah blah P2 I want a output file say "RESULT.txt" as, Value1:123456 ...
1
vote
1answer
2k views

-ksh: revenue_ext.ksh: not found [No such file or directory]

I am getting the same not found [No such file or directory] error when trying to execute a ksh script. Read tips about the PATH and running the script with a ./ in the posts here and here and tried ...
1
vote
1answer
80 views

Using kornshell or Perl to circumvent permissions needed by root

I have a problem where I need to change the ownership and permissions of one file that exists on more than 200 servers. I belong to 2 different groups and need to change the ownership from one group ...
1
vote
0answers
41 views

Learning to use ksh88 in HP-UX [closed]

I am just a plain Linux user who played some distros since 2-3 years. Now, in the company I work there's an HP-UX server. And when I get connected to it I really felt myself like a grandma seeing ...
0
votes
1answer
45 views

KSH script missinterpreting alias stored in SQL oracle DB

I have stored the path of my file in a table with as an alias (as the complete path was too long for the table's field). However, in my KSH script, when I am doing : nomtmp=`sqlplus -S bla/bla ...
2
votes
1answer
73 views

Trying to compare a variable that is multiline in a if comparison

Here is the current file I am running: #!/bin/ksh -x export BIN_DIR="../../env" . $BIN_DIR/vdenv.ksh success="DROP CREATE TABLE GRANT" $worker_dir/runsql.ksh ddl X X > chnl_avt_v1.log ...
0
votes
1answer
67 views

ksh, perform action when reaching loop maximal value

I am looking to write a small korn shell script doing 5 tests (by waiting some time before each one) and then, if they all fail, performing an action. I was looking at doing something like : for ...
5
votes
1answer
193 views

Where is $_ defined by POSIX?

In the comments to the accepted answer to this Unix & Linux StackExchange question, it is stated that $_ is "one of only some 7 special parameters defined by POSIX". I can't find that definition ...
1
vote
1answer
71 views

Is there an advantage in using ksh over zsh? [closed]

Or are there any advantages for using ksh over zsh? Would any specific commands not execute successfully across the shells or are the major differences not command related, but something else?
2
votes
2answers
498 views

KSH while loop causing issues

Hi guys I'm getting this error message when running my KSH script: ./file.sh: line 16: syntax error at line 22: `done' unexpected My code is as follows: #!/bin/ksh # count=$# #count is ...
0
votes
2answers
185 views

How to reset the file descriptor

I was trying to use file descriptor for printing the lines in the file #!/usr/bin/ksh exec 3<&0 exec 0< file.txt while read LINE do echo “$LINE” done and I am done with my code ,it ...
1
vote
3answers
458 views

Print the last-but-one field

How to print the word before the last word in line (with ksh or awk or sed or perl one liner) Example 1: echo one two three will print "two" Example 2: echo 1 2 3 4 5 6 will print "5"
1
vote
2answers
366 views

get arguments passed and put it in an array

is there a way to make the arguments passed become the element of an array? I want to access those arguments individually through array. like this: ./script.ksh arg1 arg2 arg3 then it will become ...
0
votes
1answer
912 views

is there a “goto” like command in ksh

Here is my script: #!/bin/ksh #this is where I want to go again if user enter #an answer other than "yes or no" echo "yes or no?" read ans case $ans in [yY]*) echo "yes" ;; ...
2
votes
4answers
4k views

awk + print awk output in one line

When I run the following hasys command with awk , I get output with machines names as the following: hasys -display|grep Shutdown | awk '{print $1}' machine1a machine1b please advice how to ...
1
vote
3answers
548 views

Korn Shell: Show elapsed time in a specific format

In a log file, I need to print the Elapsed time, in the following format: "Process completed %s - Elapsed %s", <time now in HH:MM:SS format>, <difference from start date to end date in ...
1
vote
1answer
217 views

How to get the JSON STRING from the given string

I have a string given below. I just need to get the first accountHeader (bolded) JSON string, I tried everything.. It didn't work. Can you help me to get the data? <START ...
2
votes
2answers
55 views

Replacing a pattern with another between first and second occurrence of a pattern in file

Want the comma's (,) replaced by the alphabet u between the first occurrence of y till the second occurrence of y. Given below is the sample input file. 100y00893225900,008932259,06,2013,NOKIA Q ...
0
votes
2answers
346 views

perl one liners + match word and delete string after separator

I work with linux/solaris machines and I need to add some rule in my ksh script: Please advise how to match the password word in file, and delete the value password after the separator "=" with perl ...
0
votes
1answer
347 views

perl one liners + print line if match last word but with space

The following perl syntax will print the line in case line was ended with "DUPLEX" But Sometimes DUPLEX have one space or more as "DUPLEX " so in this case line will not printed Please ...
1
vote
2answers
52 views

Is this an array?

I'm currently looking at an existing script that have something like this: variable='val1 val2 val3 val4' Is this another way of setting an array? If not, what is it?