2
votes
3answers
182 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
76 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
35 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 ...
0
votes
1answer
51 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
185 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
64 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?
0
votes
2answers
121 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
1answer
139 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
67 views

Help with 64-bit integers in scripts?

Maybe I'm overthinking this (although I don't think I am)....or maybe there's a neater way of solving my problem ? I have a requirement that if a file is larger than 1GB, it gets split into smaller ...
1
vote
1answer
72 views

Crontab Triple Redirect

I have a very basic understanding of redirects, but I have come across a cronjob with redirects which I do not understand. 00 19 * * 1-5 /apps/app/scripts/doit.sh a np cron > ...
1
vote
3answers
119 views

Quoting in command substitution

The command pdftk FileOne.pdf "File two.pdf" output Combined.pdf works as expected, merging PDF's One and Two. However, if I put the filenames in a file FileOne.pdf "File Two.pdf" and ...
2
votes
2answers
89 views

Replicate a directory and file names n times

I have folder which has some data (files) in that with the name 201311261418 And a file 201311261418.eob In my scenario I need to replicate this folder and file names n times with the appended ...
4
votes
2answers
4k views

Remove all files created before a certain date

I have a directory containing a high number of files (like logs for every day of the year). I would like to remove all files created before let's say 22/11. How can I achieve that ? Must I use find ...
4
votes
3answers
451 views

using awk to split a line on single spaces not multiples

I'm trying to split a line that I have no control over the format of. If parameter 7 and 8 are missing which is possible they will be replaced by a space so I would end up with, field1 field2 field3 ...
1
vote
1answer
115 views

creating variable using variable value as part of new variable name

I'm trying to create a new variable using the value of an existing variable as part of the variable name. filemsg"$word1"=" " I've also tried filemsg$word1=" " filemsg${word1}=" " on all ...
0
votes
2answers
110 views

Checking if one of 4 variables starts with string &red in ksh

I'm trying to check if one of 4 variables starts with the string "&red" and I'm struggling to get the match to work. At the moment I've got this, if [[ $filemsgCICS = "&red"* || ...
1
vote
2answers
51 views

copy a section of data from stdin [closed]

I am running a script that takes its input from stdin. This input can end up being very large so I want to extract the part I'm interested in to a temp file. The first line contains "[cics]" and I ...
2
votes
2answers
1k views

Exporting a variable with dot (.) in it

How to export a variable which has dot in it. I get 'invalid variable name' when I tried : export my.home=/tmp/someDir -ksh: my.home=/tmp/someDir: invalid variable name Even escaping metacharacter ...
2
votes
2answers
477 views

Overwriting line in unix shell after printing

How can I modify a line after printing it in unix shell.We can delete the line and write again by using \r as shown below,but how can I overwrite on existing line and not delete it completely and get ...
2
votes
2answers
199 views

Writing scripts that use different commands in different shells [duplicate]

How can I write a script that is shell independent? I want to be able to run one script which will run in ksh, sh and bash. For example: If I have a line in my script like whence ls which will run in ...
2
votes
3answers
284 views

Unexpected condition outcome in a ksh script

I'm new to shell scripting. The below code is not working. Can anyone help me on this? I've given explanation for all the lines: #!/bin/ksh cat example.txt | while read LINE # ...
1
vote
1answer
144 views

How to give variable to a KSH script with a CGI?

index.sh is in the cgi-bin directory: #!/usr/bin/ksh echo 'Content-type: text/html <html><body> <form action=FOO.KSH method=POST> <input type=submit value=fgrep ...
1
vote
1answer
428 views

How to filter an array of strings in ksh

Please advise what's wrong in my ksh code. I want to remove the IP's as defined in "bb" array from "aa" array so the IP's 255.0.0.0 and 255.255.255.0 will be removed from the list in aa array. When ...
-1
votes
1answer
55 views

Strange combination of symbols UNIX [closed]

I was looking at one korn shell script examples and I saw this strange combination of symbols: %? So my question is what does it mean?
3
votes
1answer
1k views

Installing ksh as the standard shell in Redhat: Foolhardy?

I'm not a system administrator, but my organization is considering replacing /bin/sh in Red Hat Enterprise Linux 6+ with a hard link to /bin/ksh. How foolhardy would this be? The background to this ...
9
votes
7answers
965 views

determine shell in script during runtime

As per my knowledge, to determine the current shell we use echo $0 in the shell. Rather I want my script to check in which shell it is running. So, I tried to print $0 in the script and it returns the ...
1
vote
2answers
880 views

Find all directories, in which user has access to search and echo this directories in shell

I need to find all directories, in which user has access to search(command find) and echo this directories in shell. USER is read from ksh. for example: read user I know, if user want to use find ...
5
votes
2answers
2k views

How do I escape a sub-directory name with an ampersand in it?

Running a kornshell and trying to traverse a directory tree. Want to cd to a sub-directory named as follows: -3ab_&_-3dc.img My question is HOW do I need to escape the ampersand in this name? ...
2
votes
3answers
781 views

Find directories that do not contain subdirectories

I'm writing script is ksh. Need to find all directory names directly under the current directory which contain only files, not subdirectories. I know that I could use ls -alR and recursively parse ...
1
vote
1answer
122 views

What rules govern the parent-child relationship of processes launched by shell across a pipe?

#!/bin/ksh # start_service: start the service my_server_executable 2>&1 | my_pipe_following_shell_script & exit 0 After I run the above start_service script from command line, it is ...
5
votes
1answer
127 views

Find all users who have more than N processes and echo them in shell

I'm writing a script in ksh. I need to find all users who have more than N processes and echo them in the shell. N is read from ksh. I know that I should use ps -elf, but how do I parse it, find ...
1
vote
2answers
767 views

case + how to implement equal or less or greater in case syntax

My target is to verify a range of number with (only with case + esac), and print the range. So for example: If the number is between 0 and 80, print >=0<=80 If the number is between 81 and 100 ...
0
votes
2answers
493 views

Comparison of shells? [closed]

Do shells have any actual advantages or disadvantages? They can all run any binary, they all support pipes and > (output to file). Why would one choose bash over sh, or sh over ksh, etc? Why does ...
3
votes
1answer
531 views

Why does sendmail work differently in different shells?

The following code works when I directly run it in bash shell: SUBJECT="SUBJECT-"`date`; MAIL_FROM="abc@site.com"; MAIL_TO="abc@site.com"; MAIL_CC="abc@site.com"; MAIL_FILE="/path/of/html/body.html"; ...
1
vote
1answer
97 views

Unsure about the behaviour of my script when writing to log file

I have a very simple ksh script and at certain points I want to write to a log file. I use the following commands in two places... print "Directory listing 1:\n" > ${LogFile} ll >> ...
1
vote
1answer
410 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 ...
3
votes
2answers
1k 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
861 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" == ...
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
1answer
1k 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
549 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 ...
7
votes
1answer
2k 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 ...
6
votes
1answer
365 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 ...
11
votes
7answers
631 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
2answers
3k 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
2k 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 ...
3
votes
2answers
560 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
387 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 ...
3
votes
2answers
318 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 ...
4
votes
3answers
4k 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 ...