# Shell Programming and Scripting

**URL:** https://community.unix.com/c/shell-programming-and-scripting/20.md

[Latest](https://community.unix.com/latest.md) · [Categories](https://community.unix.com/categories.md)

---

## [Process substitution explained](https://community.unix.com/t/process-substitution-explained/380709)

<div class="topic-metadata">

**Author:** [@MadeInGermany](https://community.unix.com/u/MadeInGermany)\
**Replies:** 2\
**Last updated:** [December 15, 2020, 10:46am UTC](https://community.unix.com/t/process-substitution-explained/380709 "2020-12-15T10:46:59Z")

</div>

Have you seen \<( sub shell code ) in a shell script and wonder how it works? It is called process substitution. The shell substitutes it by a special file (device or fifo). The ( sub shell code ) is run asynchronously…

---

## [About the Shell Programming and Scripting category](https://community.unix.com/t/about-the-shell-programming-and-scripting-category/138059)

<div class="topic-metadata">

**Author:** [@system](https://community.unix.com/u/system)\
**Replies:** 3\
**Last updated:** [May 27, 2023, 12:09am UTC](https://community.unix.com/t/about-the-shell-programming-and-scripting-category/138059 "2023-05-27T00:09:53Z")

</div>

Shell scripting. Post awk, bash, ksh, perl, php, python, ruby, sed, sh, shell scripts, and other shell scripting languages questions here.

---

## [My latest Python project](https://community.unix.com/t/my-latest-python-project/397552)

<div class="topic-metadata">

**Author:** [@wisecracker](https://community.unix.com/u/wisecracker)\
**Replies:** 0\
**Last updated:** [November 30, 2026, 10:34am UTC](https://community.unix.com/t/my-latest-python-project/397552 "2026-11-30T10:34:42Z")

</div>

Apologies for typos, etc; plus, it is written in a maximum of 77 characters per line to suit the AMIGA too. As many of you guys and gals know I bend rules when I code, the archive shown is no exception. I am creating…

---

## [I cried all night yesterday because I did not know how SSH remote to local port forwarding works. I do not want to be a LLM cheater, I want to be a true Linux guru like in the 80s,90s,2000s](https://community.unix.com/t/i-cried-all-night-yesterday-because-i-did-not-know-how-ssh-remote-to-local-port-forwarding-works-i-do-not-want-to-be-a-llm-cheater-i-want-to-be-a-true-linux-guru-like-in-the-80s-90s-2000s/397538)

<div class="topic-metadata">

**Author:** [@Ihattaren](https://community.unix.com/u/Ihattaren)\
**Replies:** 4\
**Last updated:** [October 30, 2026, 4:50am UTC](https://community.unix.com/t/i-cried-all-night-yesterday-because-i-did-not-know-how-ssh-remote-to-local-port-forwarding-works-i-do-not-want-to-be-a-llm-cheater-i-want-to-be-a-true-linux-guru-like-in-the-80s-90s-2000s/397538 "2026-10-30T04:50:57Z")

</div>

I feel I am a noob although I have worked with Linux servers as a CSE graduate for around 3 years. cd, ls, rm -rf all I know. bash scripts, all I know. ssh remote to local port forwarding i know. But how does that en…

---

## [Cp -r with exec of find](https://community.unix.com/t/cp-r-with-exec-of-find/397527)

<div class="topic-metadata">

**Author:** [@dextergenious](https://community.unix.com/u/dextergenious)\
**Replies:** 27\
**Last updated:** [August 11, 2026, 5:34pm UTC](https://community.unix.com/t/cp-r-with-exec-of-find/397527 "2026-08-11T17:34:17Z")

</div>

Hi, Using this simple logic to copy only directories and their content to a different location leaving the files , but it does not work as expected . It copies individual files too. What's wrong in this ? Doesn't the…

---

## [1D LEE Fast Cosine Tranform to 2D, AI helped](https://community.unix.com/t/1d-lee-fast-cosine-tranform-to-2d-ai-helped/397526)

<div class="topic-metadata">

**Author:** [@wisecracker](https://community.unix.com/u/wisecracker)\
**Replies:** 0\
**Last updated:** [July 29, 2026, 10:48am UTC](https://community.unix.com/t/1d-lee-fast-cosine-tranform-to-2d-ai-helped/397526 "2026-07-29T10:48:42Z")

</div>

I am doing various Cosine Transforms at present for a stock AMIGA A1200(HD) that only has Python 1.4.0, (a python version of 1.3.0 statically compiled exists in the Python website), so I decided to ask Gemini for help... …

---

## [Create logical association between data structures bash](https://community.unix.com/t/create-logical-association-between-data-structures-bash/397521)

<div class="topic-metadata">

**Author:** [@overcraft](https://community.unix.com/u/overcraft)\
**Replies:** 6\
**Last updated:** [July 2, 2026, 2:39pm UTC](https://community.unix.com/t/create-logical-association-between-data-structures-bash/397521 "2026-07-02T14:39:22Z")

</div>

Hi there, I have been recently experimenting with the use of data structures in my bash pipelines. In practice, I'm doing the following: #!/bin/bash #SBATCH --nodes=1 --ntasks=1 --cpus-per-task=24 #SBATCH --time=22:00…

---

## [Logrotate and split file question](https://community.unix.com/t/logrotate-and-split-file-question/397485)

<div class="topic-metadata">

**Author:** [@newbie\_01](https://community.unix.com/u/newbie_01)\
**Replies:** 8\
**Last updated:** [July 1, 2026, 10:01pm UTC](https://community.unix.com/t/logrotate-and-split-file-question/397485 "2026-07-01T22:01:34Z")

</div>

Hi, We want to use logrotate to rotate the logfile but due to the size of the logfile. We want to split the file first and then truncate -s the original file to a manageable size. Using a sample file blah.log $ du -…

---

## [Bash -c, bash and find command](https://community.unix.com/t/bash-c-bash-and-find-command/397505)

<div class="topic-metadata">

**Author:** [@dextergenious](https://community.unix.com/u/dextergenious)\
**Replies:** 11\
**Last updated:** [June 21, 2026, 8:34am UTC](https://community.unix.com/t/bash-c-bash-and-find-command/397505 "2026-06-21T08:34:40Z")

</div>

Hello, What’s the difference when we create a child shell using bash on command line and then execute commands in this shell as its childs and When we do bash –c and give commands in ‘..’. First one I know…

---

## [Aspen-Warning in calculation by Fortran](https://community.unix.com/t/aspen-warning-in-calculation-by-fortran/397508)

<div class="topic-metadata">

**Author:** [@Reza](https://community.unix.com/u/Reza)\
**Replies:** 10\
**Last updated:** [June 18, 2026, 11:14am UTC](https://community.unix.com/t/aspen-warning-in-calculation-by-fortran/397508 "2026-06-18T11:14:18Z")

</div>

Would you please tell me what I can do to solve this warning in aspen program? I want to calculate flow and mass balance for this program. \* WARNING DURING FLOWSHEET ANALYSIS FORTRAN READ-VAR VOLFLOW IN FORTRAN…

---

## [Oh boy, I never expected root in guest mode, GNU/Linux Mint](https://community.unix.com/t/oh-boy-i-never-expected-root-in-guest-mode-gnu-linux-mint/397458)

<div class="topic-metadata">

**Author:** [@wisecracker](https://community.unix.com/u/wisecracker)\
**Replies:** 7\
**Last updated:** [April 18, 2026, 3:17pm UTC](https://community.unix.com/t/oh-boy-i-never-expected-root-in-guest-mode-gnu-linux-mint/397458 "2026-04-18T15:17:48Z")

</div>

I have no idea if this is well known or not, if not then this site can claim it… Yes I know the passwords - but - and a big BUT - I should not be allowed in guest mode access to root of ANY kind AT ALL. Even co…

---

## [To format spooled output of example create user statements](https://community.unix.com/t/to-format-spooled-output-of-example-create-user-statements/397428)

<div class="topic-metadata">

**Author:** [@jonnyd](https://community.unix.com/u/jonnyd)\
**Replies:** 2\
**Last updated:** [February 8, 2026, 1:01pm UTC](https://community.unix.com/t/to-format-spooled-output-of-example-create-user-statements/397428 "2026-02-08T13:01:35Z")

</div>

Hello team, Thanks in advance for any assistance shown. Im trying to format the following example output: CREATE USER "SUP\_MBAUTISTA" IDENTIFIED BY VALUES '' DEFAULT COLLATION "USING\_NLS\_COMP" DEFAULT TABLESPACE "USER…

---

## [How to filter the command output in a better way](https://community.unix.com/t/how-to-filter-the-command-output-in-a-better-way/397425)

<div class="topic-metadata">

**Author:** [@virtherobot](https://community.unix.com/u/virtherobot)\
**Replies:** 4\
**Last updated:** [February 4, 2026, 1:33am UTC](https://community.unix.com/t/how-to-filter-the-command-output-in-a-better-way/397425 "2026-02-04T01:33:58Z")

</div>

Hi. The output of my command looks like this: virid.nix-localdisk-git-manager#0176125601 virid.nix-localdisk-git-read-replica#0176125606 virid.nix-localdisk-git-read-replica#0176125607 virid.nix-localdisk-worker-blue#01…

---

## [Html code box, on my own web site](https://community.unix.com/t/html-code-box-on-my-own-web-site/397416)

<div class="topic-metadata">

**Author:** [@klein](https://community.unix.com/u/klein)\
**Replies:** 7\
**Last updated:** [January 24, 2026, 1:49am UTC](https://community.unix.com/t/html-code-box-on-my-own-web-site/397416 "2026-01-24T01:49:01Z")

</div>

\<p\> \<div class="box"\>x11vnc -storepasswd\</div\>\<span style="color:red"\>....not as sudo/root. \</span\>\</p\> i have been leaning HTML , or trying to. a place to put things on the web, where i can find what i need. i would l…

---

## ["stty erase ^H" and "resize" commands in .bash\_profile breaking nohup](https://community.unix.com/t/stty-erase-h-and-resize-commands-in-bash-profile-breaking-nohup/397420)

<div class="topic-metadata">

**Author:** [@yanto](https://community.unix.com/u/yanto)\
**Replies:** 2\
**Last updated:** [January 23, 2026, 8:58am UTC](https://community.unix.com/t/stty-erase-h-and-resize-commands-in-bash-profile-breaking-nohup/397420 "2026-01-23T08:58:42Z")

</div>

OS: RHEL 8.10 I have a bash shell script like mytest\_script.sh (shown below) Inside this shell script, I source some environment variables using /home/oracle/.mumbo\_jumbo file. In my real-life scenario, I source /home…

---

## [Understanding Sed](https://community.unix.com/t/understanding-sed/397402)

<div class="topic-metadata">

**Author:** [@dextergenious](https://community.unix.com/u/dextergenious)\
**Replies:** 4\
**Last updated:** [December 24, 2025, 5:38pm UTC](https://community.unix.com/t/understanding-sed/397402 "2025-12-24T17:38:12Z")

</div>

Hi, I am trying to understand Sed’s functionality of internal buffers, by this simple example. Someone please help with this With simple text file named file1 having : a b c # sed '2d' file1 a c this is the defau…

---

## [Tip: multi-line history in bash](https://community.unix.com/t/tip-multi-line-history-in-bash/397399)

<div class="topic-metadata">

**Author:** [@MadeInGermany](https://community.unix.com/u/MadeInGermany)\
**Replies:** 2\
**Last updated:** [December 23, 2025, 7:09am UTC](https://community.unix.com/t/tip-multi-line-history-in-bash/397399 "2025-12-23T07:09:01Z")

</div>

In bash type a mult-line command like this: for k in 1 2 3 do echo "$k" done Now do a cursor-up, and certainly you will get the previous command in a collapsed form: a single line with semicolons as a separator. It s…

---

## [Split file based on column entries with AWK](https://community.unix.com/t/split-file-based-on-column-entries-with-awk/397388)

<div class="topic-metadata">

**Author:** [@overcraft](https://community.unix.com/u/overcraft)\
**Replies:** 5\
**Last updated:** [December 15, 2025, 10:31pm UTC](https://community.unix.com/t/split-file-based-on-column-entries-with-awk/397388 "2025-12-15T22:31:40Z")

</div>

Hi there, I have several files of the form: chr1\_contigs.txt, chr2\_contigs.txt etc. up until chr22 plus X and Y. They all originate from a big source input looking like this (I’m showing only the first three chromosomes…

---

## [xargs with rm -i](https://community.unix.com/t/xargs-with-rm-i/397389)

<div class="topic-metadata">

**Author:** [@Yori](https://community.unix.com/u/Yori)\
**Replies:** 7\
**Last updated:** [December 7, 2025, 7:50pm UTC](https://community.unix.com/t/xargs-with-rm-i/397389 "2025-12-07T19:50:58Z")

</div>

Hi, I’m trying to remember a command I used quite frequently at the time (long time ago), but I can’t remember it. The closest I am is this, but it doesn’t work. ls myfile.txt | xargs -I rm -i "{}" The order of the a…

---

## [Extract a particular pattern/string from each line](https://community.unix.com/t/extract-a-particular-pattern-string-from-each-line/397330)

<div class="topic-metadata">

**Author:** [@Francois](https://community.unix.com/u/Francois)\
**Replies:** 11\
**Last updated:** [November 27, 2025, 3:35pm UTC](https://community.unix.com/t/extract-a-particular-pattern-string-from-each-line/397330 "2025-11-27T15:35:13Z")

</div>

OS: RHEL 8.10 I have a file like below. Apologize for the long lines $ cat long\_strings.txt 13-OCT-2025 14:45:44 \* (CONNECT\_DATA=(CID=(PROGRAM=JDBC Thin Client)(HOST=jdbc)(USER=brgusx))(SERVICE\_NAME=APP\_HRTB\_P.XYZ.CH)…

---

## [Stdout and stderr combined and separate in single command](https://community.unix.com/t/stdout-and-stderr-combined-and-separate-in-single-command/397243)

<div class="topic-metadata">

**Author:** [@muhULC](https://community.unix.com/u/muhULC)\
**Replies:** 33\
**Last updated:** [November 3, 2025, 6:50pm UTC](https://community.unix.com/t/stdout-and-stderr-combined-and-separate-in-single-command/397243 "2025-11-03T18:50:43Z")

</div>

Greetings all, I am new to bash scripting. I am running Linux Mint. I am tearing my hair out trying to get the following to work: All I want to do is have the stdout and stderr outputted to separate files, and also com…

---

## [Understanding find with exec](https://community.unix.com/t/understanding-find-with-exec/396342)

<div class="topic-metadata">

**Author:** [@dextergenious](https://community.unix.com/u/dextergenious)\
**Replies:** 50\
**Last updated:** [November 1, 2025, 12:12am UTC](https://community.unix.com/t/understanding-find-with-exec/396342 "2025-11-01T00:12:23Z")

</div>

Hi, Hope you all are doing well.2 While analyzing find command with exec option operated on files in a directory , I have few questions. • Why does exec do not cause find to exit after execution of first file found, a…

---

## [Some guidance please --- how to prevent invoked script to be run on its own](https://community.unix.com/t/some-guidance-please-how-to-prevent-invoked-script-to-be-run-on-its-own/397347)

<div class="topic-metadata">

**Author:** [@newbie\_01](https://community.unix.com/u/newbie_01)\
**Replies:** 3\
**Last updated:** [October 23, 2025, 10:04am UTC](https://community.unix.com/t/some-guidance-please-how-to-prevent-invoked-script-to-be-run-on-its-own/397347 "2025-10-23T10:04:25Z")

</div>

Hi, Just want to get some tips on how to prevent a script from getting run on its own when it should have been invoked by a calling script instead? For example, we have scripts called a.sh and b.sh And a.sh inside it …

---

## [Modify a script to add the executable bit after it runs](https://community.unix.com/t/modify-a-script-to-add-the-executable-bit-after-it-runs/397264)

<div class="topic-metadata">

**Author:** [@drew77](https://community.unix.com/u/drew77)\
**Replies:** 20\
**Last updated:** [September 24, 2025, 4:58pm UTC](https://community.unix.com/t/modify-a-script-to-add-the-executable-bit-after-it-runs/397264 "2025-09-24T16:58:53Z")

</div>

Can I modify this script so it makes itself be executable ? I could use help in making my posts more visually appealing when it has code. Thanks. #!/bin/bash # Release 22.04.5 LTS (Jammy Jellyfish) 64-bit # # Much…

---

## [Assigning values with special characters to a variable](https://community.unix.com/t/assigning-values-with-special-characters-to-a-variable/397257)

<div class="topic-metadata">

**Author:** [@newbie\_01](https://community.unix.com/u/newbie_01)\
**Replies:** 4\
**Last updated:** [September 19, 2025, 4:42am UTC](https://community.unix.com/t/assigning-values-with-special-characters-to-a-variable/397257 "2025-09-19T04:42:50Z")

</div>

Hi, I need to assign to a variable a value that has special characters in them, i.e. dollar, single quote, double quote, backticks etc that may have special meaning to the shell/OS. At the moment, it appears like I hav…

---

## [Generic Comparison in Bash](https://community.unix.com/t/generic-comparison-in-bash/397256)

<div class="topic-metadata">

**Author:** [@Paul\_Pedant](https://community.unix.com/u/Paul_Pedant)\
**Replies:** 14\
**Last updated:** [September 17, 2025, 6:28pm UTC](https://community.unix.com/t/generic-comparison-in-bash/397256 "2025-09-17T18:28:06Z")

</div>

I am writing a version of HeapSort in pure Bash (Using Robert W. Floyd Algorithm), and I am struggling with a comparison operator. Each key may be integer or string, and a plain string comparison makes 13 \< 8, for exampl…

---

## [Why won't my script work?](https://community.unix.com/t/why-wont-my-script-work/396887)

<div class="topic-metadata">

**Author:** [@A\_User\_123](https://community.unix.com/u/A_User_123)\
**Replies:** 1\
**Last updated:** [September 1, 2025, 4:06am UTC](https://community.unix.com/t/why-wont-my-script-work/396887 "2025-09-01T04:06:13Z")

</div>

So I made this script to start Hyprland but the line "alacritty --hold -e " line would not run (The does work if entered manually), I do not use a login manager so maybe from the tty it does not detect a graphical inter…

---

## [Assign environment variable to a variable's name](https://community.unix.com/t/assign-environment-variable-to-a-variables-name/397233)

<div class="topic-metadata">

**Author:** [@overcraft](https://community.unix.com/u/overcraft)\
**Replies:** 4\
**Last updated:** [August 19, 2025, 10:54am UTC](https://community.unix.com/t/assign-environment-variable-to-a-variables-name/397233 "2025-08-19T10:54:34Z")

</div>

Hi there, I’m working on a pipeline (see below) where I defined a few environment variables. Also, I’m creating some on the way. In particular, I have a CONTIG variable which I wish to make univocal for each sample (ID…

---

## [Awk NR | head - fatal: print to "standard output" failed (Broken pipe)](https://community.unix.com/t/awk-nr-head-fatal-print-to-standard-output-failed-broken-pipe/397210)

<div class="topic-metadata">

**Author:** [@newbie\_01](https://community.unix.com/u/newbie_01)\
**Replies:** 5\
**Last updated:** [August 11, 2025, 12:50pm UTC](https://community.unix.com/t/awk-nr-head-fatal-print-to-standard-output-failed-broken-pipe/397210 "2025-08-11T12:50:10Z")

</div>

Hi, Just really want to know if this error is as expected. I don’t get the same error on Solaris. But as it turn out, awk is actually nawk on Solaris and gawk in Linux, i.e. /bin/awk is a symlink to nawk/gawk respectiv…

---

## [Problem with virtualbox on openSUSE Leap 15.6](https://community.unix.com/t/problem-with-virtualbox-on-opensuse-leap-15-6/397164)

<div class="topic-metadata">

**Author:** [@PaulWilliamson](https://community.unix.com/u/PaulWilliamson)\
**Replies:** 4\
**Last updated:** [August 2, 2025, 10:41am UTC](https://community.unix.com/t/problem-with-virtualbox-on-opensuse-leap-15-6/397164 "2025-08-02T10:41:01Z")

</div>

Hello! I need your help. I’m using Linux openSUSE Leap 15.6. Last night, I was working on a virtual machine when the power suddenly went out. After this unexpected shutdown, I can no longer start my Windows 10 virtual…

[Next page](https://community.unix.com/c/shell-programming-and-scripting/20.md?page=1)
