Skip to main content

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.

Filter by
Sorted by
Tagged with
1 vote
1 answer
28 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 ...
andreoss's user avatar
  • 120
0 votes
0 answers
31 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 . /...
Devansh Mittal's user avatar
0 votes
1 answer
36 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 ...
Lee's user avatar
  • 519
0 votes
1 answer
44 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 ...
Tim Boland's user avatar
0 votes
1 answer
87 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 ...
ImSahil's user avatar
-2 votes
1 answer
107 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 ...
Mr. Man's user avatar
0 votes
2 answers
106 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-...
jayvardhan's user avatar
3 votes
1 answer
89 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 ...
Yehuda's user avatar
  • 301
0 votes
1 answer
102 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....
sylvainsab's user avatar
0 votes
1 answer
57 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 ...
sylvainsab's user avatar
0 votes
2 answers
251 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 ...
Jay's user avatar
  • 1
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 . -...
const314159's user avatar
1 vote
2 answers
100 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 ...
user1093043's user avatar
-2 votes
1 answer
193 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 ...
ShyamNarayan's user avatar
4 votes
2 answers
459 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-...
lylklb's user avatar
  • 313
0 votes
1 answer
72 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, ...
DannyNiu's user avatar
  • 620
0 votes
2 answers
322 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' "...
Olivier Pirson's user avatar
2 votes
1 answer
308 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 ...
Olivier Pirson's user avatar
1 vote
3 answers
325 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-...
Lee's user avatar
  • 519
1 vote
1 answer
228 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++ ...
Lee's user avatar
  • 519
0 votes
1 answer
244 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 ...
bakunin's user avatar
  • 531
0 votes
0 answers
158 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. ...
Drsin's user avatar
  • 1
0 votes
1 answer
349 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 - $...
user3590915's user avatar
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, ...
BrassPandaSax's user avatar
3 votes
1 answer
404 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 ...
QuartzCristal's user avatar
0 votes
1 answer
93 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 & ...
shuratenko's user avatar
6 votes
3 answers
8k 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 ...
Pat's user avatar
  • 239
44 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 ...
Stéphane Chazelas's user avatar
-3 votes
2 answers
291 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 ...
Marc Le Bihan's user avatar
-3 votes
1 answer
419 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,...
Ami's user avatar
  • 1
0 votes
1 answer
221 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 ...
Jayashree's user avatar
0 votes
0 answers
85 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 ...
Jayashree's user avatar
0 votes
1 answer
67 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 ...
guest's user avatar
  • 77
1 vote
1 answer
153 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 ...
guest's user avatar
  • 77
1 vote
1 answer
380 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
Bhawneet Singh's user avatar
0 votes
0 answers
56 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 ...
KS_on_StackExchange's user avatar
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' >> ...
Mohan Babu's user avatar
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....
Dirk Horsten's user avatar
-1 votes
1 answer
473 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
ssaf's user avatar
  • 1
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 ...
ayrton_senna's user avatar
  • 1,091
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 ...
Nainita's user avatar
  • 2,912
0 votes
0 answers
157 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 ...
guest's user avatar
  • 77
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 ...
guest's user avatar
  • 77
2 votes
0 answers
151 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 ...
Kajukenbo's user avatar
  • 327
1 vote
1 answer
439 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 ...
Rafiki's user avatar
  • 111
0 votes
2 answers
507 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 ...
Mineralwasser's user avatar
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 ...
Scouse_s's user avatar
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|...
shaik's user avatar
  • 1
1 vote
1 answer
674 views

Why doesn't the terminal window title change when logging into OpenBSD from Linux Mint?

From a Linux Mint terminal window, when I ssh into OpenBSD, the terminal window title remains the same as just the terminal username@localhostname:~, whereas logging into Ubuntu the terminal window ...
Paul's user avatar
  • 517
0 votes
1 answer
477 views

Read first line split based on delimiter and store it in array (in ksh)

I am reading the first line of the file, header row, split by delimiter | and assigning it to array. IFS='|' read -r -a header < "/file_uploads/file_headers.txt" This is working fine in ...
Pat's user avatar
  • 239

1
2 3 4 5
17