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

1
vote
1answer
516 views

Linux + replace STRING/WORD in file according to rule

My target is to replace any word/string/Any characters in file with new word/string according to the following rules: If numeric characters on the left side of word/string then we not replace the ...
0
votes
1answer
328 views

linux + perl + replace any WORD in file with special characters with condition

Example1 work fine when I want to replace OLD_TEXT with NEW_TEXT ( its replace also all special characters as $@^%)(_+`:; etc ..) example1 export OLD_TEXT='$$OLD_WORD$$' export ...
2
votes
2answers
617 views

Regex for phrase matching with case statement in ksh

I am trying to start or stop a service on AIX in ksh. I am trying to start to build in fool proofing for checking things like if the services is already down, etc. Here is my script #!/bin/ksh ...
1
vote
2answers
858 views

Shell - Deal with multiple command history files

Where I work, for security and auditing purpose, we have to keep one history file for each session (user, date, terminal, etc in the file name). Obviously, the HISTFILE variable, is set to read only ...
2
votes
2answers
4k views

Bash/Korn shell script edited on Windows throws error '…^M: not found'

Some background on the issue: I am new to scripting and wrote a simple Bash script in Windows using Notepad++. cxStopAllServicesOnSERVER.sh #!/usr/bin/bash cd "/some/path" echo "Hi. Logs can be ...
4
votes
4answers
878 views

A unix command to truncate each line of a file

I have a CSV file and I want to truncate it from the third semicolon. For example, if I have this file: 1;foo;bar;baz;x;y;z 2;foo;bar;baz;x;y;z 3;foo;bar;baz;x;y;z I want to get the following ...
1
vote
1answer
305 views

Korn shell timeout/kill script

I am trying to write a simple Korn shell script to execute a loading process. The process occasionally runs into connectivity issues, so I need to kill it if it runs too long. I have been trying the ...
0
votes
1answer
760 views

Problem with using grep command with env variable containing special characters

I have a variable "abc" with value "xyz*!@#" in my unix account (ksh). I used export command to export this variable into the environment. When I use grep command as below env |grep xyz I get the ...
3
votes
2answers
833 views

Skip first 3 byte of a file

I am using AIX 6.1 ksh shell I want to use one liner to do something like this cat A_FILE | skip-first-3-bytes-of-the-file I want to skip the first 3 bytes of the first line, is there a way to ...
3
votes
3answers
537 views

What does exit do in an if block in a shell script?

I have a question regarding unix shell script. Say if you do exit 1 in inner if: will it exit or will it still execute the outer if? The following is a dummy example. if [ "$PASSWORD" == ...
2
votes
2answers
1k views

Change Korn prompt to show shorter path for working directory

I have changed my .kshrc to show my prompt as follows: 511 /export/home/students/cninja $ where 511 is the command number and ../students/cninja is the current working directory. Is it possible to ...
9
votes
4answers
2k views

Executing user defined function in a find -exec call

I'm on Solaris 10 and I have tested the following with ksh (88), bash (3.00) and zsh (4.2.1). The following code doesn't yield any result: function foo { echo "Hello World" } find somedir -exec ...
7
votes
2answers
439 views

When is it useful to use “grep — SOMEPATTERN”?

So under Linux/AIX where ever.., when is it useful to use: grep -- SOMEPATTERN the Question is the "--" part. When is it usefull to use?
0
votes
2answers
1k views

print command not found

From the korn shell, I keep getting print command not found. When I run print from the shell, it says the same thing. How would I go about fixing this? printf works fine, but for some reason print is ...
1
vote
2answers
386 views

How to set the command(s) that get run before every single prompt?

I used to know this but I forgot: I want to execute a command or a couple of commands before every single prompt. When I am in our PROD box, I want a big fat reminder above every prompt that says * ...
2
votes
3answers
879 views

Timeout `idql` command in ksh

I probably read all the threads in almost all the forums for a solution to my need. I am a beginner in shell scripting and I dont have a perfect solution yet. Below is my code snippet. idql -n ...
2
votes
2answers
2k views

What are the dangers of setting a high limit to max File Descriptors per process?

I'm working on an old legacy application, and I commonly come across certain settings that no one around cam explain. Apparently at some point, some processes in the application were hitting the max ...
7
votes
2answers
1k views

Using sed to color the output from a command on solaris

I have a ksh script that must work on both linux and solaris. I'm trying to color the output of specific commands. It works on linux (specifically RHEL6), but not on solaris (SunOS 5.10). Command ...
1
vote
1answer
727 views

Do shells support recursion?

I'm trying to write recursive functions in my shell scripts. Consider the following code: function printA { if [[ "$1" = 0 ]]; then return else echo "a$(printA $(("$1" - 1)))" ...
2
votes
1answer
365 views

Which version of unix from a shell?

I recently started a new job, and was told that I need to log on (Via shell) to a particular unix system. I'm trying to figure out a few peculiarities with the system, but first I need to know what ...
2
votes
1answer
404 views

Time validation with regex

I'd like to make validation about time stamp of one of my log file. But it seems I have problem on my expression in case statement. TIME value might be something like 11:49 or 2011. And I just want ...
1
vote
1answer
603 views

How to capitalize word (i.e. first letter to upper) in KornShell

Is there a builtin way in KornShell to capitalize a word, e.g. korn -> Korn? A Bash 4 example to clarify: str='korn' echo "${str^}" If there is not a bultin way to do this in KornShell, what is the ...
5
votes
1answer
1k views

Korn Shell: End, pgup, pgdown, and delete key not working

So basically my End, Pageup/Pagedown, and Delete key are not working in ksh93. I'm running FreeBSD by the way. My arrow keys are working, and so is my home key. Those keys work when I put this in my ...
4
votes
2answers
3k views

Colored Prompt in KornShell

According to this StackOverflow post, it is possible have a colored prompt in KornShell. I have not been able to figure out how to do this. I am able to use color: echo -e "\033[34mLinux\033[00m" ...
6
votes
1answer
323 views

Ksh features incorporated into Zsh?

I have been a user of Bash for some time. I want to learn at least one other shell now, so I have been picking up the Korn Shell. However, it doesn't look like Ksh has had major updates for almost ...
5
votes
5answers
436 views

What is the difference between $* and $@?

Consider the following code: foo () { echo $* } bar () { echo $@ } foo 1 2 3 4 bar 1 2 3 4 It outputs: 1 2 3 4 1 2 3 4 I am using Ksh88, but I am interested in other common ...
5
votes
4answers
2k views

Use a variable reference “inside” another variable

I'm sure it is relatively simple, I just don't know how to do it. #!/usr/bin/ksh set `iostat` myvar=6 I want to something like echo ${$myvar} which i want interpreted as ${$myvar} -> ${6} -> value ...
5
votes
2answers
2k views

What is the most correct way to pass an array to a function?

Consider I have a very large array $large_list, is there a way to write a function that will take the array as an argument? For example: echo_idx_array () { arr="$1" idx="$2" echo ...
3
votes
5answers
1k views

Formatting the output: Underlining

I wrote the following function in ksh that prints its first argument to the screen and underlines it with the appropriate ammount of - character: print_underlined () { word=$1 echo $word ...
2
votes
2answers
446 views

pure shell complex substitution in variable

However it may be impossible, I hope I'm just bad man reader =) Is there any way to substitute text in variables on several patterns at time or even using back reference? For example, I have ...
2
votes
1answer
335 views

KSH styling text based menu using STDERR

Is it possible to format the STDERR in order to have a better looking menu using the select command? I have a simple select select oChoice in $(<tempMenu.menu) ; do case "$oChoice" in ...
1
vote
2answers
523 views

How to get green/red terminals under OpenBSD?

For linux machines I can use: # vi ~/.bashrc # red/green terminal colors regarding exit code export PROMPT_COMMAND='PS1="` if [[ \$? = "0" ]]; then echo "\\[\\033[0;32m\\]"; else echo ...
2
votes
1answer
109 views

When is using ~+ useful?

As I understand it, ~+ means the same thing as "the current working directory". So echo ~+ should print the same as pwd. What is the purpose of this tilde expansion ~+ ?
3
votes
2answers
273 views

issues with GNU tail -f and combination of commands

$ tail -f /logs/filename.log | awk '!(/list)' I am able to run this command in GNU Linux flavour But when I written in a script it is not working. test.ksh: variable="/logs/filename.log | awk ...
20
votes
2answers
720 views

Why escape trivial characters in shell script?

I just opened a legacy shell script (written in old ksh88 on Solaris) and found the following repeated all throughout the code: [ -f $myfile ] && \rm -f $myfile The escaping backslash ...
4
votes
3answers
3k views

How to get subshell's PID in Korn Shell (equivalent of $BASHPID)

In bash you have this handy variable: $BASHPID wich always returns the currently running subshell's PID. How can I get a subshell's PID in ksh? For example see the code below: #!/usr/bin/ksh93 echo ...
3
votes
2answers
1k views

Creating a variable with sed in ksh

I'm using Ksh88 on a Solaris 10 machine. If I do the following: foo="one two three" for i in $foo; do echo $i; done The script executes as expected: $ ./script.ksh one two three However if ...
6
votes
1answer
547 views

Why does a=0; let a++ return exit code 1?

Try it: $ a=0 $ let a++ $ echo $? 1 # Did the world just go mad? $ echo $a 1 # Yes, it did. $ let a++ $ echo $? 0 # We have normality. $ echo $a 2 Contrast with this: $ b=0 $ let b+=1 $ echo $? 0 ...
26
votes
3answers
4k views

using single or double bracket - bash

I'm confused with using single or double bracket. look at code: dir="/home/mazimi/VirtualBox VMs" if [[ -d ${dir} ]]; then echo "yep" fi It works perfectly although the string contains space. ...
1
vote
2answers
255 views

$2 (field reference) in awk BEGIN is not working

In the following snippet, $2 in awk is returning empty. What am I doing wrong? I am trying to find the difference between MAX and MIN. #!/bin/ksh if [ $# -ne 1 ]; then echo "Usage: sh ...
4
votes
2answers
24k views

pdksh missing from RHEL 6 and CentOS 6?

The package pdksh does not exist on RHEL 6 or CentOS 6 when I try to install it through yum. So my questions: Why is it no longer available in the default repositories? It is available in version ...
3
votes
3answers
1k views

How do I run a script n times at same time and how do I simulate a semaphore?

I have a text file, inside of this file is a number, and I have a script.sh in ksh. The script reads the file and gets the number, then increases the number by 1 and overwrites the new number in the ...
3
votes
1answer
831 views

Unset Read Only Variables

Is it possible to unset or change a readonly variable in Korn Shell? I am using AIX 5.
0
votes
1answer
62 views

what does “serial=${serial##*.}” do? [duplicate]

Possible Duplicate: How do ${0##/} and ${0%/} work? 0:root@SERVER:/ # 0:root@SERVER:/ # serial=$(lscfg -vl hdisk1 | awk '/Serial Number/') 0:root@SERVER:/ # echo $serial ...
5
votes
6answers
557 views

Last command in ksh

In bash I can use !! to indicate the last command. In ksh I think you can use r to do something similar, but it seems to fail in one of my common patterns: typing sudo [last command]. > cp foo ...
6
votes
5answers
1k views

How to avoid a useless use of cat when parsing a file?

I have a file containing a list of directories. For instance /foo/bar/dir1 /foo/bar/dir2 /foo/bar/dir3 I want to create all these directories. Here's what I did: for dir in $(cat myfile); do ...
1
vote
2answers
964 views

put tab before every output line on AIX/ksh

0:root@SERVER:/root # echo "something" | sed -e 's/^/\t/g' tsomething 0:root@SERVER:/root # AIX/ksh .. why doesn't it works? I just want to put a "tab" before every line!
2
votes
1answer
1k views

Multiline PS1 prompt

Is the a way to specify a multi line prompt in Korn shell? I am planning to swhitch from bash to ksh. In bash I have a very simplistic prompt, but it is 2 line prompt. I hate when input position ...
5
votes
2answers
3k views

How to get a clean environment in a ksh shell?

I need to get rid of all the environment variables in a Ksh shell. I can fork a new instance, but it will inevitably source some init files (as far as I know .profile, .kshrc). Is there a way to ...
3
votes
3answers
2k views

What are the significant differences between different shells? [duplicate]

Possible Duplicate: What are the fundamental differences between the mainstream *NIX shells? If I write a shell script in bash, will it run in ksh as well? if not, what are the ...