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
95 views

how to bring exec $@ process in foreground

I want to know how docker entry point process which has started with exec $@ and has PID 1 how to bring that in foreground I tried exec $@ & but its not working, My use case: I want to terminate ...
Samurai's user avatar
  • 55
2 votes
1 answer
61 views

How to edit and execute a couple of commands from shell history?

Every now and then I want to recycle a command sequence I recently used, after I adapted it. Let's imagine, yesterday I executed foo 42 bar with some strange arguments baz /my/most/beloved/folder Now ...
Philippos's user avatar
  • 13.4k
0 votes
2 answers
693 views

How to write a process that restart again every time that it's killed

I want the exact opposite of this question. I want to know how I can create a process that keeps restarting if it's killed. Could someone give me an implementation example? For instance, let's assume ...
Lincoln's user avatar
0 votes
1 answer
40 views

Accessing interactive output of command started in crontab

I'm running a game server (Minecraft) on Raspberry Pi OS. I want the server to start whenever the device starts so I've added the following line to crontab: @reboot user cd /home/user/nukkit &&...
Leonardo Petrucci's user avatar
0 votes
0 answers
25 views

Avoid cumulative sum by Unix shell script -hdfs file copy

We are copying Hdfs directory (contains files) from 1 location to other however there is only 1 Target directory. For 1st iteration it gives correct count of file size and counts of files as in 1st ...
user2429695's user avatar
-1 votes
1 answer
48 views

Portable temporary file descriptors inside `sh -c` [duplicate]

cat <(echo yes) Displays "yes". And running this inside sh -m results in the same thing on Bash 5.2.15. Yet on Bash 4.4.20 it throws an error: sh -c "cat <(echo yes)" sh: -c:...
Zaz's user avatar
  • 2,569
0 votes
3 answers
70 views

Escaped newlines make the code work wrong. Why?

From a Markdown style guide by Google: Because most commandline snippets are intended to be copied and pasted directly into a terminal, it's best practice to escape any newlines. Use a single ...
jsx97's user avatar
  • 105
0 votes
2 answers
127 views

Pass a variable that contains a comma as a -v option to qsub

After seeing the reactions on Stack Overflow on this question and an unfamiliarity with qsub, I believe thqt U&L is better suited for this question. In qsub, we can pass environment variables (a ...
Bram Vanroy's user avatar
1 vote
0 answers
29 views

What does `:` command actually do? [duplicate]

As far as I can tell, the : command does nothing. From the bash's help :: :: : Null command. No effect; the command does nothing. Exit Status: Always succeeds. Yet, I've found some ...
annahri's user avatar
  • 2,055
-1 votes
2 answers
101 views

Avoiding subshell in conditional assignment

I'm a beginner at Linux shell, but I know that this command creates a subshell: Subshells are typically created using subshell operators or commands such as parentheses (), backticks `, or the $() ...
gremo's user avatar
  • 167
0 votes
2 answers
60 views

Remove command line options (mode-flags w/ options) from single line string in file

File mkisofs has the following one line string: xorriso -as mkisofs -r -checksum_algorithm_iso sha256,sha512 -V 'Debian 12.0.0 amd64 n' -o /srv/cdbuilder.debian.org/dst/deb-cd/out/2bookwormamd64/...
Jeremy Burcham's user avatar
0 votes
1 answer
68 views

Bash: Difference between "Pattern Matching" and "Filename Expansion" in the context of parameter expansions that do matching

Edit: Question ansewered by Gordon Davisson's comment I was reading the GNU Bash manual, and I noticed that there are basically three types of "Parameter expansion" that do pattern matching: ...
Sebastian Carlos's user avatar
0 votes
1 answer
64 views

Multichar options in Unix sysytems

I have a usecase wherein I need to support multiple character option. Currently I am using single character option for getopts. Multi-character option is desirable.What's the best way of doing this? I ...
Vatsal A Mehta's user avatar
3 votes
6 answers
726 views

Single-line shell assignment but only if variable is unset (respect null or empty values)?

When APP_ENV is "prod" then DATABASE_DISABLE_MIGRATIONS should be empty; in any other case, it should be true unless DATABASE_DISABLE_MIGRATIONS is empty or null. In other words, its value ...
gremo's user avatar
  • 167
2 votes
4 answers
284 views

Function's comment is not printed out when putting it before the function's header

A good and well-established guideline for commenting a shell function is to put it before the function's header. I am trying to follow these guidelines as much as I can, but this convention makes it ...
Rubem Pacelli's user avatar
-4 votes
2 answers
201 views

Is it possible for any shell to interpret a string with decimal point as a number (int, float)?

This idea came to me with recent updates to Visual Studio Code, in which I usually shellcheck my code automatically as well. This is what I see, so you can get the idea: This question is very simple ...
Vlastimil Burián's user avatar
9 votes
1 answer
1k views

What does >&- do in a unix / linux terminal?

I'm not too knowledgeable in the Unix command line. I found this SO answer for using the tee command without outputting to stdout, by "closing stdout" with >&- like this: echo 'hello ...
Oneechan69's user avatar
0 votes
0 answers
54 views

How to lookup the device id in audit log?

I want to find out who write the rootfs device with audit auditctl -w /var/lib -p w I got a log type=SYSCALL msg=audit(1687705400.741:250): arch=c000003e syscall=257 success=yes exit=4 a0=ffffff9c a1=...
wener's user avatar
  • 466
1 vote
3 answers
133 views

How to change modification date for files in dir to match name order?

This is a self answered question for something others also might find useful. In Dolphin, I sometimes switch between sorting by name and sorting by modification date. However, it can be annoying since ...
klutt's user avatar
  • 554
0 votes
0 answers
39 views

Change Color of Main Menu Custom Theme

I am trying to edit the text color for a selected application in the applications' menu. This "applications' menu" is opened upon pressing the Super Key. I am running pop os 22.04. As you ...
0xKnR's user avatar
  • 3
1 vote
3 answers
225 views

shell script (e.g. sed) to create mapping with character replacements

I have a variable in bash holding a string "<topic>...<topic>"representing topics that need to be mapped into a database table name, replacing illegal characters, via a mapping ...
malthe's user avatar
  • 115
0 votes
2 answers
236 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
0 votes
0 answers
49 views

Preserving environment variables (custom shell prompts) in nnn subshells

I run two different terminal emulators with different zsh prompts depending on whether I am in one or the other (with the second being the "default"): TERM_EMU=$(ps --pid $(ps --pid $$ -o ...
Andrii Kozytskyi's user avatar
0 votes
1 answer
82 views

Create files on remote hosts via ssh and sudo

Conditions h1, h2, and h3 are three Linux hosts that have joined the same Active Directory domain Account A and B are both AD account B can SSH into all hosts with no password required (Kerberos ...
DrizzleX's user avatar
  • 125
2 votes
1 answer
223 views

make xargs accept multiline string as single parameter

git log --format=%B -n 1 HEAD | xargs -I{} npx ts-node --esm ./foobar.ts {} I have this line of code, which has the purpose of using git to pass the latest commit-message to a script which will look ...
Phil's user avatar
  • 123
0 votes
1 answer
106 views

Piping output to tee breaks the conditional

I am trying to test for the presence of custom firewall-rules on servers. I am doing this by processing the iptables output with awk and returning an appropriate exit-code. This works as intended, and ...
ARMs_for_the_poor's user avatar
1 vote
3 answers
107 views

Extract specify date from a file line in shell script

I am having file `StandardDefaults.txt with contents below [MetaInfo] fileName="BUStandardDefaultsFile.dat" schemaVersion="2" schemaLocation="sftp:/var/app/napsgl/cgdata/...
Arvinth kumar's user avatar
0 votes
1 answer
613 views

How to activate python venv in a non-bash shell?

I see most tutorials/online sources advice using either source or . (a bash built-in) to activate a python venv. For example, this page suggests to do the following in Linux: cd ~/<proj_name> . ...
tinlyx's user avatar
  • 646
0 votes
2 answers
79 views

How to get the specfied output format via sh -c 'grep ...' with find -exec commands

We want to grep the corresponding files that including some fixed strings, and then output those files just only in ls -l format. For example: A) the following method with multiple -exec output both ...
lylklb's user avatar
  • 193
-1 votes
1 answer
70 views

Why do the [ -z ] and the [ -n ] flags both return true when used without an expression or when testing an unset variable? [duplicate]

From the man test pages: -n STRING the length of STRING is nonzero STRING equivalent to -n STRING -z STRING the length of STRING is zero Executing [ -n $foo ], [ -n ], [ -z $foo ], [ -z ], ...
NerdyDeeds's user avatar
0 votes
1 answer
113 views

How to use the -E option of grep matching some variable name

We want to know about the correct method for matching some variable name(including its $ prefix) via using the grep -E option. It seems that this grep macthing function can only work with either no ...
lylklb's user avatar
  • 193
0 votes
2 answers
181 views

Which file descriptor numbers are safe to use in (POSIX) shell scripts?

Chapter 3.6 Redirections of the Bash manual says: Redirections using file descriptors greater than 9 should be used with care, as they may conflict with file descriptors the shell uses internally. ...
finefoot's user avatar
  • 3,010
2 votes
1 answer
185 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
0 votes
0 answers
34 views

How to properly format the command argument for sudo? [duplicate]

I have a command that is similar to this minimal example: $ sh -c 'echo "1=$1"' _ foo 1=foo $ When I want to run it through sudo, it stops working: $ sudo -i -u user -- sh -c 'echo "1=...
finefoot's user avatar
  • 3,010
0 votes
1 answer
127 views

Shell script not picking up variable in if statement

I have some code that looks like this: ################### - Let's call this section 1 if [ -n "$STUFF_JAVA" ]; then __LAUNCHER="$STUFF_JAVA" else __LAUNCHER="...
Chicken Sandwich No Pickles's user avatar
0 votes
0 answers
62 views

BASH: Is there a way to READ the current foreground and background color in use? Not CHANGE them... just see what the user is using NOW? [duplicate]

Some background for any who find this later This is a question about colors being applied in the shell. NOT about how to CHANGE said colors (there's a bajillion answers for that). But how to READ them....
NerdyDeeds's user avatar
-2 votes
1 answer
64 views

shell script when set e and o not run right

the bellow code, when e and o set sample time,then the last line not run, why? set -x set -e set -o pipefail add=$(echo 'x' |grep '1x' | wc -l) echo $add echo '1'
zouyy's user avatar
  • 1
-2 votes
3 answers
349 views

Bash Read First Line of File with Variable Assignment

Unity has a variable assignment in a file called "ProjectSettings/ProjectVersion.txt" but when I try to read it, it tries to run and throws an error. The first line of the file is ...
kirbycope's user avatar
0 votes
0 answers
27 views

Why will use the script the Bourne Shell instead of the written bash? [duplicate]

I write a script who should login to a server via ssh and do something there. So I write two parts. First part: myLoginPassword="loginpassword" sshpass -p $myLoginPassword ssh -t user@...
SWP-Sebastian's user avatar
0 votes
2 answers
34 views

How to truss the combined commands via some predefined variable?

If we use the combined commands directly in the truss arguments, it works fine without any problems. However, if we use the predefined variable of the combined commands indirectly in the truss ...
lylklb's user avatar
  • 193
3 votes
0 answers
108 views

Are there any Linux distros with a preconfigured user-friendly shell environment?

I see so many Linux distros all around, and they all come with different look & feels and their own set of pre-installed GUI tools for most standard tasks. The default shell environment, however, ...
carlfriedrich's user avatar
0 votes
1 answer
38 views

shell arguments with spaced passed as files instead of commands [duplicate]

I have read this Q&A, but it seems to always think the parameter as file. I want to transform the command diff <(ls old) <(ls new) from this link to one function which receive two arguments, ...
zg c's user avatar
  • 3
1 vote
1 answer
113 views

How to trace file descriptor duplication?

I am learning to use redirection. the typical operation is like below: command > file 2>&1 Refer to APUE 3.10 and 3.12, I think the critical syscall sequence is like below: open(...
Yao Li's user avatar
  • 21
0 votes
1 answer
67 views

How to read files of kind "-diary.txt-" using echo?

I have a file named "-diary.txt-", I need to get it's content. When trying to read it using echo < "-diary.txt-", it returns a blank string. I did some research, and came up ...
Nikita Re's user avatar
7 votes
1 answer
639 views

Why does tar's handling of stdout and - differ?

After a comment from OP, I discovered that /dev/stdout gives blocks of 10 KiB even after disabling buffering, but - does not. Why is this? I could not find anything regarding this in man tar nor man ...
wjwrpoyob's user avatar
  • 440
-1 votes
1 answer
105 views

why does using &(bg) before &&(and) gives me error in bash script [duplicate]

[[ -n $program ]] && echo "$program" && setsid $program "$arg" & && exit 0 gives me "syntax error near unexpected token `&&'" [[ -n $...
Yogesh's user avatar
  • 1
2 votes
1 answer
385 views

Piping continuous output into rofi

I'm trying to write a bash script to pipe strings into rofi. These strings are continuously generated by a function gen_x. The function gen_x sometimes (only when a condition is met) outputs new ...
Friendly Penguin 123's user avatar
0 votes
0 answers
29 views

Why does my sourced script only work once? [duplicate]

I'm currently trying to refactor a software of mine. I wrote this script: shopt -ps cdable_vars . ~/.config/butler/butler_aliases while getopts 'a:' OPTION; do case "$OPTION" in a) ...
OddDev's user avatar
  • 101
1 vote
1 answer
415 views

What is the difference between .shrc and .profile?

I want to try out Bourne shell on FreeBSD so I am starting to set it up for my use. In .shrc, I set my prompt, enabled vi mode, set some aliases, and exported some variables. However, I see that ....
Vladimir's user avatar
  • 169
5 votes
2 answers
3k views

Understanding "side effect", or multiple commands within one command?

This question focuses on POSIX compliant shell script. It is common to increment a variable by: i=3 : $(( i += 1 )) echo "return code = $?" # return code = 0 echo "i = $i" ...
midnite's user avatar
  • 423

1
3 4
5
6 7
241