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.
12,161
questions
4
votes
4
answers
116
views
BASH - Find file with regex - Non-recursively delete number-only filenames in directory
I'm wanting to non-recursively delete all files in a directory where each filename contains only numbers, using only a single line of BASH.
I somehow accidentally ran a shell script with commented out ...
0
votes
0
answers
4
views
Pass the parameters to install rkhunter using ansible
Trying to install rkhunter using ansible i am getting errors while trying to install, need support to run the commands
hosts: all
gather_facts: no
become: true
tasks:
name: Changing the directory ...
0
votes
0
answers
44
views
Redirecting output to file removes newline [duplicate]
I wrote two different C codes.
hello.c
#include <stdio.h>
int main(){
printf("Hello World\n");
}
hello2.c
#include <stdio.h>
int main(){
printf("Hello World")...
1
vote
6
answers
415
views
Bash script that takes multiple path arguments and checks if files can be successfully created there
I would like a bash shell script (for my Debian 12 system) which accepts multiple paths as arguments, and then checks if a file can be successfully created in each one. Then the result should be put ...
0
votes
1
answer
33
views
Fish shell add args to $EDITOR using export
How can I add args to the command I use as the $EDITOR in fish shell? Specifically using the export EDITOR=... syntax rather than the set command.
I want to do something like export EDITOR='code --...
-2
votes
1
answer
51
views
How does bash <command-argument> work?
About bash
For a new tty when is executed the echo $SHLVL command it displays 1 as expected. Now, if in the same tty is executed the bash command and later again the echo $SHLVL command it displays 2. ...
0
votes
0
answers
30
views
Not able to login to a user through another user in Vagrant
I have a main user scriptbox where all three other web01, web02, web03 are connected.
Web03 is an ubuntu based VM and other two are centos. They are running fine but web03 is not doing, it keep ...
4
votes
0
answers
86
views
Does the shell's & operator perform redirects before or after starting asynchronous commands?
Consider the following script:
rm -f /tmp/bar
echo foo >/tmp/bar &
tail -f < /tmp/bar
When processing the echo line, does the shell first perform the redirect opening /tmp/bar for writing ...
1
vote
1
answer
134
views
bash: script running in pm2 unable to access file descriptors files at /dev/fd/
I have script script.sh:
#!/usr/bin/env bash
# pm2 seems to always run in `bash` regardless of `#!`
echo "running in $(readlink -f /proc/$$/exe)"
# Redirect to both stdout(1) and stderr(2)
...
1
vote
2
answers
42
views
how to correct "unknown root shell" in shell in a box
I'm having problem of directory due to a typo in a command I wrote in my command
I made a typo while writing this command
chsh -s/usr/local/bin/bash/<username>
instead of using this chsh -s/usr/...
0
votes
0
answers
41
views
`$SHELL` still points to `/bin/sh` over SSH after `chsh -s $(which fish)`
I am using OpenBSD-current. After doas pkg_add fish, I ran chsh -s $(which fish) to change the default shell of my user qys to fish, and it works:
$ /usr/bin/ssh magicbane
Last login: Wed Aug 21 11:17:...
-3
votes
1
answer
59
views
what is a "string" in bash? [duplicate]
i keep hearing people talking about "strings"?
what is a string? what are people talking about?
i keep hearing "enter a string" or "if your string this" or your "...
0
votes
0
answers
31
views
how to pass script arguments in ansible
I am trying to install rkhunter rpm file using ansible,unable to pass the arguments for the below commands
sh installer.sh --layout /usr/local --install
rkhunter --update
rkhunter --propupd
rkhunter -...
0
votes
2
answers
38
views
How to capture exit code of subshell (while in pipe)
somefile contains this:
aaa
bbb
ccc
This is the subshell which can exit before completing all iterations. In my particular case is while but it could be for or until:
cat "somefile" | while ...
0
votes
0
answers
30
views
Bash misinterpreting lenght of PS1 when using ANSI escape sequences [duplicate]
if i use the following
export PS1='\033[36m$ \033[0m'
Bash misunderstands the length of the prompt and starts line-wrapping too early. My assumption was that it is counting every character, but ...
0
votes
0
answers
42
views
what is a "flag" in bash? and how is it different then other options? what would be a good example to highlight the difference? [duplicate]
so i keep hearing that a flag is a TYPE of option, and that the only difference between a flag and normal options is that a flag is a type of "boolean" option, which when explained to me ...
0
votes
0
answers
9
views
VSCODE: how to open file in current window while DISPLAY is set to display of ssh server
I am ssh'ed to a server. I use a software that is triggered through the CLI and has a GUI. So I did setenv DISPLAY <$DISPLAY value of the server>. Now this software works fine.
But I also have ...
0
votes
2
answers
33
views
How can I set a restricted shell for a user, while allowing cd to user-owned directories?
I've setup restricted shell(s) on an Arch-based system by creating /usr/local/bin/rzsh and /usr/local/bin/rbash:
these scripts cd into /home/$USER and then invoke zsh -r and bash -r respectively, but ...
6
votes
3
answers
2k
views
Why does editing '/etc/shells' file using 'sudo open' shows an error saying I don't own the file?
zsh=/bin/zsh
sh -c "echo $zsh >> /etc/shells"
sh: /etc/shells: Permission denied
OK, fine. And if I add sudo, it works. Fine.
zsh=/bin/zsh
sudo sh -c "echo $zsh >> /etc/...
1
vote
3
answers
123
views
Linux command vs bash command, is my understanding correct?
this question may be a bit terminological.
As a new Linux learner, I find many tutorials mention Linux/bash commands. To my understanding, commands are just various programs and bash is a shell like ...
0
votes
0
answers
53
views
No username in terminal after creating user with no home directory
I create a new user on a Debian system with the following command:
root@mydebian:~# useradd -M -p mypass -u 1001 myuser
I deliberately don't want to create a home directory, so pass in the "-M&...
0
votes
0
answers
34
views
How can I archive my website for offline/online use (wget) that needs multiple domains?
I'm trying to archive an old PHP website offline. The goal is to have all the website data in one folder ...
So that I can browse through everything offline
I can upload the folder and then browse ...
-4
votes
1
answer
79
views
Moving file with date using Unix command
I want to move all .XML files in the current working directory whose name starts with DAPRETAIL followed by the current date in YYYYMMDD format to a separate directory.
I tried:
DATE='date +%Y%m%d'
mv ...
0
votes
0
answers
25
views
SGID in File Permissions
the following are two scenarios to let you know how i understand the problem and the SGID:
Scenario 1:
user A is part of the group G.
group G has full privileges to 2 files-its the group owner of ...
0
votes
3
answers
76
views
My shell script exits if I try to mount from within the script an already mounted drive How can I make my shell script resume?
This is what happens.
I manually and successfully mount my USB drive using mount /media/usb from outside a shell script which I wrote. Therefore, the drive is working and mounted normally.
The very ...
0
votes
1
answer
43
views
how to write a std out to a unique temporary file name and use the same to mail out
I have a script that works as expected. It basically runs a bunch of other scripts and redirects the output to a file, once every part is done, I mail the output file and delete the same. In recent ...
0
votes
1
answer
49
views
When is the ENV variable set
according to POSIX, the ENV environment variable is used to specify initialization files to be read (such as some kind of .profile and .rc files), but if this variable is used to specify these files, ...
0
votes
0
answers
37
views
pushd within a pipeline says it's adding to the stack, but it's not? [duplicate]
I'm working on a modification of this approach to automatically saving and restoring bash's directory stack state when using pushd and popd.
For some reason, my code to restore the saved state isn't ...
3
votes
2
answers
525
views
How to limit the number of files printed by ls and print them in columns like ls prints normally?
Here is extension of the question: How do I limit the number of files printed by ls?
with additional condition: how to print results in as many columns as fit to the current terminal width — as ls ...
0
votes
3
answers
68
views
Splitting Words into space separated characters [duplicate]
I have a table with one word in each row. I want to split the word into space separated c h a r a c t e r s. Is there a way to do that via bash command?
If yes, I also have a table with multiple words ...
0
votes
0
answers
62
views
Trailing slash in GNU and BSD cp and find commands
What might be a reason that BSD cp and find don't "like" a trailing slash for directory names?
| | cp | mv |
|-----|--------------------------|...
0
votes
0
answers
60
views
Why is `mv -f source target` so much slower than `rm -f target && mv source target`
I got a case where I need to overwrite some file with another and noticed a very significant slowdown when using "mv -f" if the target already exists and is being read. More specifically, ...
-2
votes
2
answers
48
views
Remove last 9 character in alternate lines of file in unix
I need to remove last 9 character from a file starting from Line number 4 and remove only on alternate lines 6,8.. like that to last Line of file
3
votes
1
answer
150
views
How to overload / customize bash (or any other shell) commands handler?
When in bash some non existing command is run, corresponding error message appears:
$ non-existent-command
non-existent-command: command not found
Is it possible to customize this behavior?
I would ...
2
votes
1
answer
44
views
What does POSIX's third exception to the application of `set -e` mean?
The POSIX shell standard gives three exceptions to the application of set -e:
The failure of any individual command in a multi-command pipeline shall not cause the shell to exit. Only the failure of ...
1
vote
1
answer
27
views
Autocomplection with description in zsh
General overview
This question complete this other one.
I try to set an autocomplete for --test parameter who should suggest a list of possible values (Here “foo” and “bar”). Until theire, it pretty ...
0
votes
1
answer
42
views
Is the idea of having a login shell and a non-login shell merely a way of making user preferences? [duplicate]
Scouring the internet about the difference between a login shell and a non-login shell, it turns out that the ultimate difference is merely the files that are being sourced. A login shell sources some ...
3
votes
2
answers
375
views
"history" command ordered by most common
Can I get the output of history sorted in order of most-used?
I know how to do it in a programming language, but not from the shell. In my case I'm on macOS with zsh.
I know I could use uniq and sort ...
0
votes
5
answers
123
views
What is the difference between using code $variable and ${variable}2?
What is the difference between using code $variable and ${variable}2 ?
Example:
file ='GLOBAL_AR_COLLECTOR_COMMENTS20240614ALYSSAB.TXT'
prefix ='GLOBAL_AR_COLLECTOR_COMMENTS'
In my shell script code ...
3
votes
1
answer
453
views
What is the precedence of operators '=', '||'
In this command, if curl succeeds, then res will be set to the output of curl. It seems = has higher precedence than ||.
res=$(curl -s "http://example.com")||true
But || should have higher ...
1
vote
1
answer
35
views
omz reload in zsh widget
I am using zsh+oh-my-zsh and I am using the following code to change .zshrc using a hotkey and I am trying to reload omz after the change:
function f() {
# ... update .zshrc here ...
omz reload
}
...
1
vote
1
answer
36
views
zsh autocompletion for parametre value
General overview
Here is my auto complexion file:
_triumphum_complete() {
_arguments \
'(- 1 *)'{-h,--help}'[show help options]' \
'(- 1 *)--tui[Run the game selection interface]' \
'(- 1 *)'{-r,...
8
votes
3
answers
711
views
Is there an equivalent of caniuse for commands on posix systems?
I'm thinking about using a callout to the jq command in a utility script I'm writing, rather than parsing JSON manually.
In order to make the script as portable as possible, I want to know which ...
0
votes
1
answer
42
views
Get a list of all user's commands from a non-interactive shell
I am writing a script that would automatically suggest some new aliases/functions to be added to a user's shell config. Before doing that, however, I would like to make sure the aliases being ...
-3
votes
1
answer
74
views
How to convert multiple columns to rows in shell (unpivoting)
I have a tab separated table with hundreds of columns and rows, like that:
OTUId AC0184 AC0250 AC0257 AC0258 AC0262 AC0263 AC0289 AC0293
OTU549024624 51659 0 0 0 0 0 0 0
OTU565712448 108 0 0 0 0 0 0 0 ...
0
votes
1
answer
33
views
Linux Shell Script replace last shown lines at the screen, not write it under the last once
i run a script from bring formated numbers to the screen :
#!/bin/sh
while true ; do
echo
awk -v x=987654321 -v n=8 'BEGIN{srand(); while (--n) {$++NF = int(rand() * x / n); x -= $NF}; $++NF =...
0
votes
1
answer
50
views
join a specific number of files/devices in linear mode together in a linux system
For joining in Linux files/devices in linear mode together i have this script dm-joinlinear.sh from
join files/devices in linear mode together in a linux system , thanks telcoM
#!/bin/sh
usage() {
...
2
votes
1
answer
222
views
Joining 'fish shell' arguments into a single string with spaces
Sorry, this question is already answered for 'bash' here:
Joining bash arguments into single string with spaces.
in Fish, using "'$*'" leads to this error:
$* is not supported. In fish, ...
0
votes
0
answers
17
views
How do I determine if a path is a fifo? [duplicate]
I have some bash shell code that runs
if [[ ! -s "$1" ]]
to determine if $1 is a non-empty file
This test fails if $1 is a fifo, even though the fifo has data in it ready to be read.
Is ...
-1
votes
3
answers
94
views
Delete 2-line paragraphs, keep 3-line paragraphs, maintain newline between all
On a Linux machine with GNU tools I have an ascii file that consists of only 2-line and 3-line paragraphs, each paragraph separated by a newline. All 2-line paragraphs are to be deleted so that all 3-...