Questions tagged [shell]

The shell is Unix's command-line interface. You can type commands in a shell interactively, or write scripts to automate tasks. Use this tag for questions applying to /bin/sh and most compatible shells (ash, bash, ksh, zsh, …). For shell scripts with errors, please check them in http://shellcheck.net before posting here.

Filter by
Sorted by
Tagged with
1 vote
1 answer
118 views

why is iotop showing "?err"

when I run iotop, the second column "PRIO" shows ?err everywhere. What does this mean? I did not find any mention of err in the manual page. I am using custom compiled kernel. Could it be ...
user avatar
0 votes
1 answer
47 views

How to use if function in shell scripts?

I need to use if function to filter out required files only when using SFTP to copy files to my server from a remote server. Here is my try to get the all data inside /filesnew. #!/bin/bash files=`...
user avatar
  • 51
0 votes
1 answer
125 views

convert a uint8 array ( javascript new Uint8Array() ) to binary format (or binary mode ?) in shell / bash?

The question is about convert from new Uint8Array() generated from javascript into a normal file (file that can be used with other programs like ffmpeg) ** I don't know the right term to use if it's ...
user avatar
  • 115
1 vote
1 answer
36 views

Please explain to me how these files connect to each other

So I have two files here. The first one is random.sh, which is: #!/usr/bin/env bash n=$(( RANDOM % 100 )) if [[ n -eq 42 ]]; then echo "Something went wrong" >&2 echo &...
user avatar
0 votes
2 answers
102 views

Grep text between two patterns on each line including the pattern

Have these lines: [2022-04-14T20:06:17+0800] [ALPM] installed data (0.5.0-7) [2022-04-14T20:06:17+0800] [ALPM] installed data-cleo (0.4.1-4) [2022-04-14T20:06:17+0800] [ALPM] installed python (0.2.2-...
user avatar
1 vote
1 answer
44 views

Using rsync to backup system data gives "No such file"

I'm trying to backup my entire system directory using the following script: #!/bin/bash cd / BACKUP_LOCATION=/media/data/backup/system-backup/ echo Backing up system data to $BACKUP_LOCATION, ...
user avatar
0 votes
1 answer
31 views

Which shell command returns Java's home path?

I'm aware of the which command but when I run it on Java, I get the following path: $ which java /bin/java What I'm looking for, I think, is the Java path I get when I run the following Maven command:...
user avatar
0 votes
1 answer
18 views

shell access to cPanel user

I have a VPS hosting with WHM/cPanel access and I have root SSH access where I need to run commands from time to time. I have cron jobs there which are currently running as root, but what to switch to ...
user avatar
0 votes
0 answers
33 views

UNIX shell script to check the status from oracle table and move the file to appropriate direcoty

I have a requirement to loop through sales files in UNIX and then check the status of file in oracle table (status column in svc_posupld_status table) . If the status is C then move the file to "...
user avatar
  • 37
0 votes
0 answers
21 views

How can I turn off history in xonsh?

There is a tutorial here: https://xon.sh/tutorial_hist.html but it seems to be wrong. Some of the documented history commands work: root@backup ~/bin # history id ...
user avatar
  • 101
2 votes
1 answer
71 views

Adding custom field to the subject line in a opensssl X509 certificate via command line

I am attempting to generate a CSR for a certificate and wish to include a unique id as part of the certificate subject line. this information shall be used by the TLS client for some purpose after the ...
user avatar
  • 155
-4 votes
2 answers
66 views

The correct way to embedd a bash script into another bash script [closed]

Please suggest or correct the following code or make it simpler if possible. The file must be a embedded inside the single shell script file. Embedded.sh #!/bin/bash echo '#!/bin/bash read input while ...
user avatar
-1 votes
1 answer
108 views

How can I remove the start and the end with sed?

How could I remove first ./ and the end / from my path? right now my code has: sed -i 's/dir2\/file-example.json//' test.sh and it prints out like this: ./dir1/ but I would like to have it like this: ...
user avatar
0 votes
1 answer
120 views

Bash script with subcommand and long options only

How can I use getopt or getopts with subcommands and long options, not with short options? I know how to implement short and long options with getopts. Solutions that I've found so far are using ...
user avatar
1 vote
0 answers
8 views

Queue interactive commands and attend to then in sequence

I want to have a script that adds commands to some kind of queue. I then want to run those commands interactively one at a time. More commands should be able to be added to the queue while I'm ...
user avatar
  • 11
2 votes
2 answers
81 views

Environment variable with command substitution isn't getting set correctly

I'm using Windows 10 WSL (Ubuntu 20.04) and trying to get a command working but having trouble with setting an environment variable. I need to run: export ADB_SERVER_SOCKET=tcp:<variable ip here>...
user avatar
0 votes
0 answers
28 views

why does find alter matching behaviour when -exec is appended here? [duplicate]

Consider the following: /tmp/tmp.DkL0R4v7RR$ find . -regex '\./spam' -o -regex '\./eggs' ./spam ./eggs /tmp/tmp.DkL0R4v7RR$ find . -regex '\./spam' -o -regex '\./eggs' -exec ls \{} \; ./eggs /tmp/tmp....
user avatar
  • 753
2 votes
1 answer
166 views

Zsh runs precmd after I run a command

For some reason, zsh's precmd runs after commands instead of before them...? [user@main ~/workspace]$ cat ~/workspace/precmd.sh echo "Command should start after this line, but it will not" [...
user avatar
  • 21
2 votes
1 answer
44 views

What value is expanded in an indirect expansion?

In the manual page for bash, the indirect expansion for a parameter that is not a nameref is explained as If the first character of parameter is an exclamation point (!), and parameter is not a ...
user avatar
0 votes
0 answers
33 views

dpkg: Ctrl-C in shell for examining conffile conflict

When dpkg encounters conflicts in conffiles, the user may press Z to "start a shell to examine the situation". In this shell however, Ctrl-C seems to be disabled or intercepted, which can ...
user avatar
  • 761
0 votes
1 answer
51 views

Source a script in Linux for all users logging in that echo some things

We have CENTOS 7.x Linux with bash shell. I need a some environment variables to be set and some messages involving these env vars to be echoed (a banner kind of thing, but dynamic because it's got ...
user avatar
2 votes
2 answers
146 views

Sort files by modification date, then by name

Let us assume a directory that contains pictures from different cameras: DCIM1234.JPG DCIM1235.JPG DCIM1236.JPG DSCN4120.JPG DSCN4121.JPG DSCN4122.JPG DSCN4123.JPG IMG5840.JPG IMG5841.JPG IMG5842....
user avatar
2 votes
4 answers
302 views

cmp command return value?

I am using the cmp command on Ubuntu and I would like some clarification on its return value. The manual ($ man cmp) says nothing about the return value, but suggests looking into the GNU ...
user avatar
  • 264
1 vote
1 answer
73 views

Why is the prompt shown at the top of the terminal, rather than at the bottom?

Why am I asking this? As you can guess, it's mostly for curiosity. But why did the curiosity spring up in my mind? Well, there's been a moment when I noticed that I was not happy that after I'd run ...
user avatar
  • 1,012
0 votes
3 answers
82 views

How to copy specific directory name to a file

So I have a few directories and I want to copy only the name of the directories that start with 'k' and end with 'g' to a file. How do I do that?
user avatar
1 vote
1 answer
151 views

POSIX (or portable) way to forward emails from crontab

I've got an installer/updater script that's meant for IRIX/Linux/macOS/FreeBSD and I would like to extend its compatibility to Solaris. I've already fixed a few parts that weren't POSIX compliant, ...
user avatar
  • 405
1 vote
0 answers
45 views

How merge two directories? [closed]

For example i have dirA, dirB - all with subdirectories. I want to merge dirA into dirB with "force" dirA. I tryied to use this /usr/bin/rsync -avh --progress dirA dirB But "force"...
user avatar
0 votes
0 answers
33 views

How to fix error add user on remote machine with ssh

I am having a problem. I have 2 servers 10.84.70.132 and 10.74.70.131, on each server there are 2 similar scripts, a.sh and main.sh. a.sh is responsible for adding a user and giving ownership of that ...
user avatar
0 votes
0 answers
31 views

how to mix old with new content in copy / move

Supposing that I have the following dir scheme in origin: 00 │   ├── 1 │ │ ├── a.c │ │ ├── b.c │ ├── 2 │ │ ├── a.c │ │ ├── c.c And in tmp the new scheme, that I want to mix with ...
user avatar
0 votes
5 answers
507 views

How to add double quotes to every value in env file

I have an .env file and need to copy to an .env.sh file. The command exports to .env.sh file: scriptPath=$(dirname "$(readlink -f "$0")") printenv | sed 's/^\(.*\)$/export \1/g' &...
user avatar
3 votes
0 answers
85 views

What parts of dash are not part of the POSIX standard?

I know that dash adheres quite closely to the POSIX standard, but I know that it's not 100.00% strict POSIX without any extras. The shell that comes closest/adheres exactly to the POSIX standard is as ...
user avatar
2 votes
1 answer
75 views

What's the differences? (command substitutions) [duplicate]

printf "%s" `echo ../.. | sed 's/[.]/\\&/g'` printf "%s" $(echo ../.. | sed 's/[.]/\\&/g') printf "%s" "$(echo ../.. | sed 's/[.]/\\&/g')"
user avatar
0 votes
1 answer
53 views

Why ~/USERNAME/bin/some_custom_command does not work as expected?

I read "Linux Bible 10th Edition", chapter 3: Using the shell, at 70 page. There is Tip section: If you want to add your own commands or shell scripts, place them in the bin directory in ...
user avatar
  • 135
0 votes
1 answer
39 views

How to Control Number of Parameters Entered to Function

I am trying to make a simple menu-driven calculator script. I want there to be an error message displayed whenever the user does not enter the correct parameters when they call the add() or subtract() ...
user avatar
0 votes
2 answers
279 views

when i chsh to zsh it seems to get replaced with fish (garuda)

I ran a fresh install of garuda dragonised,it comes with a fish shell by default. I had no experience with this so asked the installer to add zsh -which it did along with config files. Upon booting ...
user avatar
  • 131
2 votes
1 answer
86 views

Detect last iteration of loop in POSIX sh

In POSIX sh, is it possible to detect the last iteration of a for loop within the loop? I am trying to fill in the blank in this example code: #!/bin/sh items='1 2 3' for item in $items; do echo &...
user avatar
  • 1,962
2 votes
1 answer
35 views

count variable not getting incremented

I have a scenario where I am running the following code: error_count=0 (cd tmp1 && terraform init -backend=false > /dev/null && terraform validate && echo "Terraform ...
user avatar
  • 85
0 votes
1 answer
35 views

Loop multiple video files to compress them all in one directory?

I'm new to linux. I need some help. I want to compress all files present in a directory with same extension. The output should be with same name and extension. I want to run a shell loop to do this. ...
user avatar
0 votes
3 answers
42 views

How can I delete the rows after a specific grep line in BASH

I have this output from Linux. Size: 8192 MB Locator: CPU0 Bank Locator: DIMM01 Size: No Module Installed Locator: CPU0 Bank Locator: DIMM02 Size: 8192 MB Locator: CPU0 Bank Locator: DIMM03 Size: ...
user avatar
1 vote
2 answers
41 views

Echo contents of for loop automatically

I often use a for loop to i.e. convert a bunch of file formats. In some cases, where text transformations or variables occur, it would be nice to check if the substitutions were performed correctly. ...
user avatar
  • 187
2 votes
2 answers
138 views

What exactly handles the Ctrl+X shortcut family (e.g. Ctrl+X Ctrl+E) in Linux terminals?

I've seen a lot of online resources mention several compound shortcuts beginning with Ctrl+X : Ctrlx Ctrle : Edits the current line in the $EDITOR program, or vi if undefined. Ctrlx Ctrlr : Read in ...
user avatar
0 votes
2 answers
18 views

How to extract the first backup id from a shell output to a variable?

[user@laptop ~]$ cf adbr list-backups database Getting backups of database Backup ID Time of Backup bbf4277f-889a-4a9a-9274-683ed6e1553c_1647592205 Fri Mar 18 ...
user avatar
  • 3
0 votes
1 answer
81 views

How to verify the setup to see if the user can read and modify the file

Here's the homework question: Create 3 users Jack, John, Xander, and create 2 groups: Family and Friend. Add the user's Jack and John to the Family group, and add Xander to the Friend group. Set up a ...
user avatar
  • 75
2 votes
2 answers
671 views

Prepare shell script for output to file and console

I know that there is a possibility to use tee to copy the contents of output to a file and still output it to the console. However, I can't seem to find a way, to prepare shell scripts (like a fixed ...
user avatar
  • 123
0 votes
0 answers
93 views

I updated python 3.9 in linux mint 20.3 by default and command line doesn't work, no taskbar

Yesterday I installed Python3.9 in linuxmint-20.3 and I changed by default (before I had python3.8.3), and when I restarted the computer, I could't open the command line, there was no taskbar, and the ...
user avatar
0 votes
1 answer
65 views

Question about the command "sudo su - (username)"

So I have a task I'm supposed to do and I need to login using a username I have created, which I did sudo useradd (username), and also added a password using sudo passwd (username), which all worked ...
user avatar
  • 75
0 votes
0 answers
29 views

How change login prompt for headless Linux to ask for more than just username/password?

We want to setup a headless Linux box but have it force users to enter in more than just a username and password. Is there a way to add our own custom questions and then grab/verify the info entered ...
user avatar
0 votes
1 answer
80 views

Using positional arguments with grep

I'm trying to apply positional arguments to make it easier to copy/paste strings when looking for content in files of my project. This command works fine: grep myString -R . but this command does not:...
user avatar
0 votes
2 answers
40 views

move recently created files matching a pattern from one folder to a different one

I am looking for a bash script example which does the following: I have files being written under /tmp folder I do at the xterm prompt, ls -ltr which gives me a list of recent files such as: ...
user avatar
  • 3
0 votes
2 answers
32 views

Sorting by fourth column

I have a CSV file filename.csv with the following contents. filename.csv: "Afghanistan","94.0","81.1" "Bahamas","42.9","43.2" "Bolivia (...
user avatar
  • 11