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
0 votes
1 answer
24 views

How does a trap affect external programs?

When a subshell is entered, traps that are not being ignored shall be set to the default actions Source: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_28 Apparently,...
  • 2,260
0 votes
2 answers
90 views

What is the necessary configuration for enabling tty access for shell on Linux Kernel initramfs?

While echoing, e.g. echo "serial tx to ttyAMA0" > /dev/ttyAMA0 shows output towards serial console terminal on Linux initramfs loaded to /dev/ram0 on an arm64 platform, there's no ...
0 votes
2 answers
29 views

get latest file on github via script

I am trying to do the same for https://github.com/eneshecan/whatsapp-for-linux/releases as is described here: Download and install latest deb package from github via terminal but cant get it to work, ...
  • 45
-1 votes
1 answer
29 views

How can I format the output of a shell command into columns, but limit the number of columns created?

Say I run systemctl | grep running | column -t I get an output that looks like this: init.scope loaded active running System and Service Manager session-...
  • 119
0 votes
1 answer
24 views

Any CLI pager that display full-screen optionaly (when prompted to)?

I've been using less forever now, and there's one thing I wish it was doing differently. When I do git log --pretty=oneline --abbrev-commit it switches to full-screen immediately (as the output is ...
  • 111
0 votes
1 answer
21 views

Exit out of Insert mode in Bash with Vi keybindings on command run

I have bash set up with Vi keybindings, however when a command finishes running it returns to insert mode rather than movement mode. I can use bind '"\C-M":vi-movement-mode' in my .bashrc to ...
0 votes
2 answers
37 views

Nested command inside xargs

I have a folder of folders of folders of files. I'm trying to copy all the files to their parent. The following command doesn't work because dirname "{}" executes before the find command. ...
0 votes
1 answer
21 views

Bash: dirname not working with xargs

The following command: echo ./test/test2/test23 | xargs -I "{}" echo `dirname "{}"` Outputs: . (not as expected) The following command: echo ./test/test2/test23 | xargs -I "...
2 votes
1 answer
124 views

Stop and Start Shell Script

I have created a simple script to start a process, but I am not sure how to add a stop step since the process is ran/stopped manually Currently, to start the process, we use a single command line ...
1 vote
1 answer
35 views

Finding the occurence of a word in a subfolder

Hello i'm trying to find all occurrences of a word in a subfolder. While that seems to be easy i want that for each occurrence we will display the path and the name of the file followed by ' -> ...
  • 15
0 votes
1 answer
18 views

"xargs -I" not working for child command

xargs -I not working for child command Example: # Not working ls .... | xargs -n 1 -I % sh -c "cmd $(cmd2 % )" # working ls .... | xargs -n 1 -I % sh -c "cmd % " Is there any ...
  • 1
0 votes
1 answer
28 views

How to send expression with variables over ssh?

I can run the followind loop locally for i in A B C; do mycommand $i; done Now I am trying to send it over ssh The following version ssh myhost for i in A B C; do mycommand $i; done The following ...
  • 2,977
0 votes
0 answers
16 views

How to escape command line to be able to send it by `ssh` to remote host in all cases?

I am composing command line for ssh with the following (Python) code: def instrument(self, cmd: str) -> str: return "ssh -A %s" % (cmd) and this of course failing in some cases, for ...
  • 2,977
0 votes
0 answers
23 views

Adding file-user in shell-script

I'm trying to add users with code like this: asadmin start-domain asadmin create-file-user --groups=user --target=server-config -authrealmname=file --passwordfile=password.txt a asadmin create-file-...
0 votes
1 answer
43 views

Shell: Why is there a "duplicate process " on using a pipe and tee?

I'm not very familiar with bash process, and was surprised to see a "duplicate" process running while using pipe and tee. Can you help me understand this? In the following, the path to the ...
  • 1
0 votes
1 answer
63 views

How does "done < file" work in a while loop?

While trying to learn how to manipulate the content of files in bash, I encountered the following code example: while IFS=, read -r col1 col2 do echo "I got:$col1|$col2" done < myfile....
0 votes
0 answers
63 views

Luci openWRT UCI firewall rule update without position number

Hey all I have been trying find some code that would allow me to update my firewall rule via the UCI. The way I am currently adding the new rule is like this: uci add firewall rule uci set firewall.@...
  • 121
0 votes
0 answers
22 views

shell script does not recognize alias even source bashrc where alias are defined [duplicate]

in ~/.bashrc /etc/bashrc, I write alias multiscp='/root/deploy/multiscp.sh' and in command line, I could use multiscp like a command multiscp xxx However, in a shell script, multiscp is not ...
  • 135
5 votes
1 answer
874 views

What does command eval "$(/opt/homebrew/bin/brew shellenv)" actually do?

Homebrew requires us to add eval $(/opt/homebrew/bin/brew shellenv) to ~/.zprofile. What does this actually evaluate to and what does this accomplish? I am a bit new to shell scripting. I know $var is ...
0 votes
1 answer
62 views

how do I handle a specific output from systemctl?

I am a beginner with bash/shell scripting and I am trying to handle a specific output that comes from systemctl when a specific service is not found. For example, when I run systemctl status xyz the ...
  • 3
0 votes
1 answer
32 views

Confused about java -version [duplicate]

For every program/utility on Unix, I would type the name of the program followed by --version to check its version, like so program --version If I understand correctly, the double dash -- is used to ...
  • 111
0 votes
0 answers
19 views

Can't enable IPv4 forwarding via adb shell

I've got a rooted Android phone and am trying to enable IPv4 forwarding via adb shell. If I do host$ adb shell phone$ su -c "echo 1 > /proc/sys/net/ipv4/ip_forward" then it works just ...
0 votes
2 answers
51 views

Extract value from broken JSON output in Shell

Once I list the backup files from a server, It throws me the output as follows: { "backupFiles": [ "XYZ_Backup_2.0.0.0-417_2022_08_14_12_10.gz", "...
0 votes
0 answers
33 views

How to write regular expression for apt-get so that it excludes package conflicts?

I am trying to install all packages that contain font in their name. I tried apt-get install *font* but packages fontforge and fontforge-nox conflict each other. How should I revise my regex so that ...
0 votes
1 answer
63 views

keep 2 newest files on folder and delete others

I have a backup folder on my server with autogenerated files. They are consuming 100% of my disk. So i need to create a cron that delete all files but keep the 2 newest. I have found a code that might ...
  • 11
0 votes
6 answers
128 views

search pattern and print in same line

I have a big .txt file in below format Pin name="AR_OP" status="f" Pref x=997.6800 y=2327.0400 side=N width=0.0400 depth=0.3750 / Layer id=1 -- Pin name="...
  • 129
0 votes
3 answers
54 views

Combine .csv-files with different amount of lines

Here I asked already for a similar problem. Now I have 3 .csv-files but one of them has only 1 line. file1.csv dog cats mouse file2.csv 001a 002a 003c file3.csv WORD The output should be dog,001a,...
  • 157
1 vote
1 answer
37 views

Combine .csv-files with text between each line

I have two (or maybe more) files: file1.csv dog cats mouse file2.csv 001a 002a 003c If I use paste file1.csv file2.csv the output is dog 001a cats 002a mouse 003c Of course I can use paste -d ,...
  • 157
0 votes
2 answers
40 views

Copy only the folders (and all their content) at the level of source path with rsync

I have the following tree, where f are files while src and d are directories (f could be hidden or not): src/f1 src/f2 ... src/d1 src/d2 src/d3 ... I want to replicate the same structure in a dst ...
9 votes
1 answer
829 views

What does a hyphen do next to the argument position in bash shell script? Like ${1-}

I've come across this piece of code from here: #!/bin/bash # ... if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then echo "Usage..." exit fi I understand what this does is print the ...
0 votes
0 answers
56 views

Zsh: make single file selection smart, stylish, and functionally correct (highlights, completions below cursor, etc)

I would like to have a near-flawless "single file selector" with zsh. So far I haven't seen one in questions as they tend to focus on zle settings for one's command line. Let's say we are ...
  • 546
1 vote
0 answers
17 views

Disk usage command not producing expected number of outputs

I want to run disk usage command (du) on both a parent directory (to find the total of all its contents), and then additionally on one of its subdirectories only. If I try to pass multiple paths into ...
  • 174
0 votes
0 answers
70 views

Trying to change "non command" color in kitty terminal (ver. 0.21.2) using the fish (ver. 3.3.1) shell with the oh-my-fish theme slacker

I've been trying to change the color of non-command such as the picture below (the uncompleated 'help') link to the theme im using in omf: https://github.com/maqboolkhan/omf-theme-slacker my kitty....
  • 25
0 votes
0 answers
19 views

Simple ssh/telnet shell for debugging remote embedded device

I have an embedded device running some aarch64 Linux build, with busybox, but without sudo, nc, sshd, telnetd, /dev/tcp, /dev/udp, etc. I would like to be able to remote in to run bash commands and ...
0 votes
1 answer
51 views

Cron job to run rmmod not executing at reboot

This is on Proxmox VE 7.3 with Debian 11. I ran crontab -e, added @reboot /home/onboot.sh to the file, saved it, ensured cron is running with systemctl enable cron.serviceand verified it's running at ...
0 votes
1 answer
7 views

install --compare is said to, in some cases, not modify the destination at all - but in which cases?

The man page for install describes the --compare option like so: -C, --compare compare each pair of source and destination files, and in some cases, do not modify ...
  • 203
-3 votes
3 answers
69 views

shell script - checking multiple lines if value is smaller than

I have input files (.txt oder .csv) In this files are different values (sometimes no value -> ""). If ONE of this values is less than 0.001 (or empty -> "") the output should ...
  • 157
1 vote
0 answers
51 views

A script causes a parent script to stop

I have a third-party script that runs some complicated stuff. I run everything from an ssh session (the machine is a headless VM running Ubuntu 20.04). When I run it interactively, it runs normally. $ ...
  • 406
0 votes
0 answers
31 views

shell stdout to two command and program is stuck

I have a sample shell command to calculate array percentile number $ time zcat input.txt.gz | head -n 999999 | awk 'BEGIN{FS="\t"}{print $13}' | st --percentile=97.5 75 real 0m3.532s ...
  • 23
0 votes
1 answer
28 views

variable contains $, expansion needed

The script fetches the path of a file via some command and then the mount command runs. pkgname= #defined here su -c "apkfile= #defined here &&\ stockapp=$(pm path $pkgname | sed -n '/...
  • 140
0 votes
0 answers
15 views

Is the concept of file permission only applicable when access is via shell? [duplicate]

So in Linux we have a concept of file permission. There are three classes: user, group, and others, and there are three types of permissions: read, write, and execute. Now consider this. You are on a ...
-1 votes
1 answer
63 views

Is the concept of file permission only applicable when access is via shell?

So in Linux we have a concept of file permission. There are three classes: user, group, and others, and there are three types of permissions: read, write, and execute. Now consider this. You are on a ...
0 votes
0 answers
53 views

While loop in root shell

I want to get data from a file which can be read by root only and do some operations on the data. the code is su -c "grep $variable $file | while read -r line; do echo $line | xargs -r umount -l; ...
  • 140
1 vote
1 answer
55 views

use aliases in bash script

I use aliases in my code, it works the first time and shows the current time, but the second time, when I call it shows past time(time showed before instead of current time) GNU nano 6.2 ...
1 vote
1 answer
76 views

How do I enable colours by default for common utilites in PowerShell on (Gentoo) Linux?

I'm currently running Gentoo Linux and have installed PowerShell (app-shells/pwsh-bin) as I am a contrarian. That being said, I am unable to obtain colour by default when running certain commands. ...
  • 13
0 votes
0 answers
26 views

How to run ssh commands on a host after mounting via sshfs and avoid 2FA? [duplicate]

I have the following situation. I am able to ssh into a server but it requires 2FA each time I ssh into the server. Let's say that I do not have control over the server's configuration to disable/...
  • 101
0 votes
2 answers
41 views

Delete files with similar names

I have been away from scripting for years, so I was wondering if someone can help in the below. I am migrating from Google Photos to Amazon Photos (about 40k photos). Here is an example of what I ...
1 vote
0 answers
36 views

How to check whether a shell process has job-control enabled?

Is there a way to programmatically check whether a given (shell) process has job-control enabled?
  • 1,736
0 votes
0 answers
67 views

Terminal closes itself when running many python processes

I was trying to run multiple machine learning experiments simultaneously to save time. My OS is Fedora 36, and I use emacs. To automate the experiment I used runs.py import subprocess subprocess.run(&...
  • 103
2 votes
2 answers
80 views

Is there a character in Linux that can be used at start of a filename to bump it to the top in regular sort order but doesn't require escaping etc?

There are lots of questions/answers explaining what characters one shouldn't use in Linux filenames etc. I am looking for a non-alpha/numeric character that I can put at the front of a filename to ...