Questions tagged [ksh]
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.
820
questions
0
votes
1
answer
72
views
Cut command failing
We have a ksh Script that is suppose to give the output as last day of the month but when ever we run it we get the below error:
cut: fields are numbered from 1
Try ‘cut —help’ for more information,
...
0
votes
2
answers
142
views
Find command slow when I'm not piping into awk
I have a script I've used for many years for building a list to some directories, with the following lines:
##Find all scenarios for this sector number
find /gsgt/source/scenarios/AT_* -name ${...
1
vote
1
answer
38
views
ksh: How to execute command before user input is executed?
I want to update the window title to the name of the command currently being executed in a terminal running ksh.
In bash I could use a special signal trap
trap __update_title DEBUG
In zsh I could use ...
0
votes
0
answers
32
views
Concatenating 2 environmental variables in a ksh script [duplicate]
I have a storage.src file with the following 2 environmental variables exported
export FIRST="HelloHelloHello"
export SECOND="World"
I have a .sh file as follows
#!/bin/ksh
. /...
0
votes
1
answer
38
views
What is a good way to perform a SHA256d hash (double SHA256) on an OpenBSD fresh install?
What is a good way to perform a SHA256d hash (double SHA256) on the default terminal of an network isolated OpenBSD fresh install?
Here's what I'm doing:
echo test > testfile
cat testfile | openssl ...
0
votes
1
answer
55
views
Bash Shebang scripts with a .ksh extention
I have inherited shell scripts that have a bash shebang...but for some reason have a .ksh extension.
The creator of these scripts is no longer here and I cant find any reason in Google.
Why would he ...
0
votes
1
answer
111
views
How to stop the while loop after four hours in shell script, if the file not found?
I am working on the ksh script where I am getting the file from the sftp server & copying to local & checking if the file is available there or not. I am running this on loop if the file is ...
-2
votes
1
answer
125
views
Assign multiline string to variable in script [duplicate]
I want a variable, let’s say PS, defined in my .profile file with the following value:
PS1='PWD: ${PWD}
$ '
So that when I enter $PS in my terminal, I get a two-lined prompt string, the first line ...
0
votes
2
answers
125
views
Removing Minutes from Date as a Variable
I am writing a script in KSH and need your help to find the logic to remove minutes and seconds from the date.
If users pass 2024-12-22-16-43-40 to a variable, it should be converted to 2024-12-22-16-...
3
votes
1
answer
90
views
How does my function break `functions`?
I wrote a ksh function for git checkout (I've removed some irrelevant proprietary components for the sake of the public question, if you're wondering why it's useful to me):
# Checkout quicker
...
0
votes
1
answer
109
views
shell one-liners for bulk-renaming multiple files
I am looking for two renaming one-liners to manage my music library.
First concerns filenames. I would like to use as simple as possible names,
that is : %track %title.ext
for instance 01 Song name....
0
votes
1
answer
64
views
ksh88 string substitution in alias | mpv streaming [duplicate]
tl;dr how can I substitute a string (i.e. a youtube/streaming url) in an alias such as alias mpvyt='yt-dlp <URL> -o - | mpv - ' ?
I live in a mezzanine studio using a M1 macbook for a ...
0
votes
2
answers
270
views
How to check the headers between 2 CSV files in unix?
File1 - filename.csv
File2 - filename.csv
I wanted to compare the headers between these 2 files in linux using a ksh script.
case 1:-
Say,
the header of file1 is INPUT -->
NAME,UNIT CODE, VAR
...
0
votes
0
answers
30
views
Process substitution, variable substitution and wildcard expansion [duplicate]
I have this code:
if (( i == 0 )); then
findCommand="find . -name \"${id}*0${month}*\" | sort -r | head -1"
else
findCommand="find . -...
1
vote
2
answers
113
views
Adding a newline above PS1 that survives prepending
In OBSD ksh, I had a PS1 which prepended a blank line:
PS1="\n[\u@\h] \w\n\$"
The problem with this was that pyenv prepends the name of a virtual environment when that environment is ...
-2
votes
1
answer
200
views
"for" loop is not executing on the remote server using SSH
The below "for" loop works locally on the same server.
But when triggered through "ssh" protocol on remote servers, the output is not received.
Please, can anyone suggest how to ...
4
votes
2
answers
468
views
Why does ksh93 not support the %T format specifier of its built-in printf in AIX?
We have tested the following commands with ksh93 printf in many AIX 5.3/6.1 systems, but they all failed with the same result.
Why is that?
#
# oslevel -s
6100-07-09-...
0
votes
1
answer
78
views
Is KornShell pattern a regular expression?
KornShell pattern extends POSIX shell "glob" patterns (i.e. *, ?, etc.) with repetition specifiers such as *(...), +(...), as well as negation among many nice features.
In a hobbist project, ...
0
votes
2
answers
404
views
Bash and other shells $(...) remove the ending newline character [duplicate]
Why the shell structure $(...) removes the ending newline character?
#!/bin/bash
S='a
b
'
printf '%i [%s]\n' "${#S}" "$S"
T=$(printf '%s' "$S")
printf '%i [%s]\n' "...
2
votes
1
answer
351
views
if var='value' then in Zsh: Is it really a valid syntax without semicolon?
The following code works on Zsh 5.8 that I tried, despite the missing semicolon. But is it really a valid Zsh syntax?
#!/bin/zsh
if var='value' then
echo 'then'
fi
Without an assignation that ...
1
vote
3
answers
385
views
ksh parameter expansion: replace / with -
Say I have this:
str="@test/string"
echo $str
@test/string
echo ${str#@}
test/string
works as expected, but
echo ${str//\//-}
ksh: ${str//\//-}: bad substitution
fails. (expected @test-...
1
vote
1
answer
234
views
OpenBSD: npm install sodium-native, interpret error messages
I am attempting to install sodium native as an npm package on OpenBSD 7.3 amd64.
Aside: As a dependency of Hypercore, Hyperbee and Corestore.
This needs node-gyp.
Following this, I set the C and C++ ...
0
votes
1
answer
276
views
Writing a ksh-script with a predefined time-out
My OS is AIX (7.2) and my shell is ksh88 (preferably) or ksh93, if necessary.
I want to write a script that sets some maximum timer for its execution. If it manages to finish its task within this time ...
0
votes
0
answers
175
views
Having problem using uuencode in script
I am using below command and it works:
uuencode stats.txt stats.txt | mailx -s "users" [email protected]
But when I put same command inside my shell script, it does not work.
I dont have email. ...
0
votes
1
answer
389
views
Switch user using EOF does not work su - ${instance} <<'EOF'
I am running a ksh script from root where I switch (su) to different users and execute the commands. But, some reason EOF does not. Here is part of my code.
This part of the code does not work su - $...
1
vote
1
answer
68
views
Why does enclosing a command in double quotes affect aliases?
I have an alias rm='/bin/rm -i' and I know that if I type "rm" filename in the command line, the alias will be ignored somehow and the normal rm command without the -i flag will be called, ...
3
votes
1
answer
405
views
Why is "${1-"$var"}" (option 6 down below) not mentioned in POSIX?
The only reference I could find in the spec is this:
It would be desirable to include the statement "The characters from an enclosed "${" to the matching '}' shall not be affected by ...
0
votes
1
answer
99
views
Issue - infinite loop using while on ksh script
I'm writting a scsript to automate some check at work & i have trouble on only 1 standing issue which is the script never ending.
It do the all task over & over.
There are 2 while loop & ...
6
votes
3
answers
9k
views
convert file to utf-8 based on the file command
Have an upload process, reads the file and using sqlldr it uploads the data to DB. I was getting invalid number issue while processing the file in sqlldr. Found the file is in UTF-16 format and then ...
46
votes
1
answer
10k
views
What's wrong with var=$(</dev/stdin) to read stdin into a variable?
We've seen a few posts here lately that use this:
var=$(</dev/stdin)
in an attempt to read the shell's standard input into a variable.
That is however not the correct way to do it on Linux-based ...
-3
votes
2
answers
306
views
I'm using bash on Debian 11. But how may I open a Bourne, Korn or C-Shell if I am willing to?
I am reading a book speaking about Bourne Shell (the ancestor of bash = Bourne-Again Shell I'm currently using), Korn Shell and C-Shell.
I was curious, and willing to experience them.
On a bash ...
-3
votes
1
answer
431
views
Awk variable passing error
Below works fine:
awk '{print $1,$2,$3,$4,$5,$6,$7,$8,$57,$9,$55,$10,$11,$12,$56,$13,$53,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$40,$41,...
0
votes
1
answer
231
views
how to check for specific string in a file named abc.txt and write that missing string to another file (xyz.txt) using a shell script?
For example, generally I need to check for 5 strings. (Note : the strings are in file format .txt)
file1.txt
file2.txt
file3.txt
file4.txt
file5.txt
but there are 3 strings in abc.txt
file1.txt
...
0
votes
0
answers
100
views
filewatcher script in ksh script
I wanted to edit a already created filewatcher script with the given logic
the source file path is stage path (stage/filewatcherwrap.ksh)
there are 4 files in the below given format in stage path
...
0
votes
1
answer
68
views
set -o vi in prompt leaves insert mode every time I use arrow keys and has warning bell constantly (bash/ksh)
I might use arrow keys to go back and edit a flag when typing a command in my prompt and doing so constantly kicks me back from insert mode to normal mode. How do I turn this off so it matches the ...
1
vote
1
answer
164
views
Confused why pgrep can't show children of jobs started in subshell
I need to use korn shell for a script I'm writing and ran into issues managing nested child processes. The example code below demonstrates my issue. In it I create a temporary file for x seconds, then ...
1
vote
1
answer
422
views
Read content of file in ksh and split it by ','
My file.txt contains the following content:-
./raw_input/0009/img.raw,./raw_input/0009/calib.raw
0
votes
0
answers
57
views
Korn shell (ksh) omits closing quote when displaying aliases
When displaying aliases in Korn shell (ksh) the closing quote is omitted.
This happens with both predefined and user-defined aliases:
>> alias type r l ltr
type='whence -v
r='hist -s
l='pwd; ls
...
0
votes
3
answers
1k
views
Concatenate files with same structure, keeping header only for 1st file
I want to merge 28 files with different names and the same data structure, using the script below:
$ cp mohan.csv Consolidate.csv
$ for fname in line
do
cat $fname | sed '1d' >> ...
1
vote
1
answer
3k
views
Call a command from a shell script, passing most arguments, allowing arguments with blanks
I am have a wrapper run_sas.sh around a command sas that runs SAS code in batch. A typical call looks like this
./run_sas.sh -sysin /my_code/my_program.sas -log /my_log_folder/my_program.log
run_sas....
-1
votes
1
answer
497
views
One master ksh file to call 2 ksh script files [duplicate]
I have 2 ksh (korn shell script) : file1.ksh and file2.ksh; and I want to have a master file ksh script that will call the 2 files; what's the code I have to put in my master file?
Thanks
0
votes
5
answers
1k
views
How to ignore all text containing special character more than once?
Sample Input:
apple_ig
rabbit_cat_ig
dog_ig
bird_duck_ig
orange_ig
goat_ig
Expected output:
apple_ig
dog_ig
orange_ig
goat_ig
I need to ignore all data that contains underscore _ more than once in ...
0
votes
3
answers
1k
views
Script to keep the latest 5 files and rest will be moved to other destination
Source path:
/var/log/
Here I have 4 folders named ad1nrld,ad2nrld,icp1rmnrl,icp2rmnrl
I can move all the files to the other destination named /home/spsy/logs_bkp. But I want to keep latest 5 files in ...
0
votes
0
answers
158
views
How to keep track of PID of multiple active scripts that spawn multiple bacground processes
I have some programs that that need to run in order with a common task between each program that modifies the data and sends it to another location for processing. each modify_data script spawns ...
1
vote
1
answer
1k
views
grep with many patterns from file and show which pattern matched which file without rereading files
I have n separate non fixed greps against m files. I only need to know if there is at least 1 match in each file, but I need this for each pattern. I currently make n separate greps so I can merge ...
2
votes
0
answers
163
views
How to start xterm instance which automatically opens nvi in a "complete" environment with ^Z :suspend capability
I am having problems starting a xterm instance that automatically opens nvi in a "complete" environment with job control.
I am referring to xterm specifically here and not a VTE skin or ...
1
vote
1
answer
462
views
Display branch name in $PS1 on ksh88
I want to display my current git branch in the prompt in ksh88.
I'm working on a legacy project, when the backend run on IBM's AIX, with a mandatory ksh88 shell. I can switch to say, bash, for some ...
0
votes
2
answers
542
views
ksh on AIX - pwd in prompt does not update when changing folders
I'm very new to AIX as well as ksh, but I currently have some downtime at work and am trying to configure my prompt to be both colored and show my current location.
At the moment, I get the correct ...
1
vote
2
answers
3k
views
How can I append new lines in a CSV file and modify them in Unix
I am new to Unix in general and starting to learn shell scripting. I am working with a CSV file with the below sample rows (it's a large CSV file with 4 entries for each item):
Table 1
Item ID Time ...
0
votes
3
answers
41
views
How to nullify multiple columns at specific positions?
Input-
FN|LN|ADD|STATE|PIN|CONT|GRP|PCN|BIN|TOKEN72|TOKEN73|TOKEN74|TOKEN75|ndc|ncpdpd
FN1|LN1|ADD1|STATE1|PIN1|CONT1|GRP1|PCN1|BIN1|TOKEN721|TOKEN731|TOKEN741|TOKEN751|ndc1|ncpdpd1
FN2|LN2|ADD2|...