Skip to main content

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
2 answers
51 views

SSH shows double shell prompt after entering a command

As you can see in the example below, the shell prompt is duplicated after I use a command. I tried changing the PS1 to something simpler, but the same issue continues to occur: PS1="\u@\h:\W\$ &...
0 votes
0 answers
41 views

How do I check the status of an LSB service? [duplicate]

If I run service --status-all I see a list of all services, including the service (let's call it X), that I'm interested in Status of X: X is running with the PID Y If I then do service status X I ...
44 votes
6 answers
134k views

Running chsh does not change shell

I want to change my shell from bash to zsh. I have tried running the following while logged in as user zol: $ chsh -s /bin/zsh $ sudo chsh -s /bin/zsh zol $ su -c 'chsh -s /bin/zsh zol' # The above ...
0 votes
3 answers
4k views

How to get the json data used in each curl statement while using xargs and maps it to its corresponding result?

I have text file that has arguments of curl command. This is how the file looks 'https://example.com/tl/' -X POST -H 'Content-Type: application/json' --data-raw '{"email":"username2&...
4 votes
1 answer
2k views

Run vsim from dmenu — it only works when directly invoked in the terminal

Works: vsim, sh -c vsim Doesn't work: echo "vsim" | sh, echo "vsim" | xargs -I {} sh -c "{}" I want to run ModelSim (vsim) with dmenu, which is triggered using xbindkeys. Details vsim is a ...
0 votes
0 answers
14 views

Saving ZSH history across SSH sessions

Is it possible to keep zsh history consistent across SSH sessions to the same machine? To explain further, let's say I opened an SSH session to another computer, ran mkdir test-dir/, and exited the ...
-2 votes
1 answer
49 views

Watch command but with shell

I want use shell and see watch on top parallel without switching to another tty. Is theres way to do that?
3 votes
2 answers
8k views

How to export proxy in Redhat Linux 7 using the current login credentials?

I need to export proxy on RHEL 7 with the current logged user credentials. I am able to achieve this by adding manually in .bashrc or .bash_profile.: export http_proxy=http://username:password@proxy....
-2 votes
2 answers
124 views

How to make bc handle explicitly positive numbers? Or what alternative calculator can be used with such support?

Consider the following: $ echo "-1" | bc -1 $ echo "(1)" | bc 1 $ echo "+1" | bc (standard_in) 1: syntax error Minus sign and round braces are handled correctly but ...
21 votes
2 answers
8k views

List of shells that support `local` keyword for defining local variables

I know that Bash and Zsh support local variables, but there are systems only have POSIX-compatible shells. And local is undefined in POSIX shells. So I want to ask which shells support local keyword ...
2 votes
1 answer
243 views

How quotes work in bash regex expression? (Regarding special regex reserved character & special bash reserved characters.)

Is there any special bash reserved characters in bash regex expression? ex: eg: if [[ $url =~ ^https:\/\/www\.youtube\.com\/playlist\?(.+&)?list= ]]; then echo "URL matches the regex"; ...
0 votes
3 answers
94 views

How to add a prefix to every element of an array in shell

I am reading inputs from user in my script with spaces, and those multiple inputs I want to use in a command further down by adding -l in front of each one of those inputs. Is there a way to do this ...
1 vote
1 answer
612 views

comapre two array values equal or not | index to index |

I have a scenario where I want to compare value of array1 and array2 echo "${array1[@]}" gives me output1 : 12.12 10.1 echo "${array2[@]}" gives me output2 : 12.12 10.1 how to compare array1 ...
0 votes
2 answers
1k views

How to write a function that takes parameters and flags in arbitrary order?

I am new to shell and I was trying to write a custom function that takes regular arguments, as well as parse any flags provided. test_it() { flag1="false" flag2="false" ...
1 vote
2 answers
3k views

Source additional files on login (~/.bash_profile? ~/.bashrc? /etc/profile? /etc/bashrc?)

I've a few special aliases and such set up on a few servers (CentOS 7, bash shell). Some of them are server specific (ex: what IP point to the internet, hostname of the server, etc), while others are ...
37 votes
6 answers
75k views

In a regular expression, which characters need escaping?

In general, which characters in a regular expression need escaping? For example, the following is not syntactically correct: echo '[]' | grep '[]' grep: Unmatched [ or [^ This, however, is ...
26 votes
4 answers
51k views

How do I handle switches in a shell script?

Are there some built-in tools that will recognize -x and --xxxx as switches (flags or "boolean options", rather than "ordinary arguments"), or do you have to go through all the ...
2 votes
2 answers
53 views

set -o xtrace for just one line? [duplicate]

bash 4.4.20(1) on RHEL 8.4. set -x ; ./blarge ; set +x works, of course, but it's just that much more stuff to remember to remove when you're finished. And gets sticky if you're running ssh, sudo, ...
-8 votes
0 answers
57 views

Shell Script to write server status [closed]

Need a shell script to check process running on multiple hosts like tomcat, Httpd and Filebeat process
5 votes
1 answer
927 views

Why does 'jobs' always return a line for finished processes when run in a subshell within a script?

Normally, when a job is launched in the background, jobs will report that it is finished the first time it is run after the job's completion, and nothing for subsequent executions: $ ping -c 4 ...
2 votes
6 answers
32k views

how to send a mail with attachment using sendmail command in unix

This is how I try to send, email with sendmail command. echo "Dear user, please find the attached file. Thanks, Support team " | mailx -s "x12 extract for 837 transaction" -a $LogFilePath/file.csv $...
-1 votes
1 answer
56 views

How to specify several alternative conditions (OR operator) for single case statement? (Or Alternatively, where is shell case syntax description?) [duplicate]

I want something like this: time="1m" case "$time" in *h*) *m*) *s*) echo "handling several cases for h, m, s tokens" ;; *) echo "...
1 vote
1 answer
50 views

How to store and source environment variables when they contain semicolon (`;`) [duplicate]

I'm trying to exchange environment variables and restore them quickly between terminals. I define two functions in my shell (~/.bashrc): save_env(){ mkdir -p ~/tmp printenv > ~/tmp/env } ...
20 votes
5 answers
24k views

Keep exit codes when trapping SIGINT and similar?

If I use trap like described e.g. on http://linuxcommand.org/wss0160.php#trap to catch ctrl-c (or similar) and cleanup before exiting then I am changing the exit code returned. Now this probably won'...
-1 votes
3 answers
2k views

Arithmetic in a bash script

In a bash script, I would like to determine the maximum or minimum value depending on my input: for example if my input is max 20 40, then the output should be 40. If the input is min 20 40 then the ...
1 vote
1 answer
137 views

How Can I Add Short Arguments to a Shell Script

To add options, I have the following in one of my scripts: parse_opts() { while [ $# -gt 0 ]; do case "$1" in -h|--help) help=1 shift ;; -r|--...
0 votes
0 answers
13 views

How to assign stdout of subshells to variables in a platform agnostic way [duplicate]

I have discovered that on Sun 10, /bin/sh does not support $(...) syntax for variable assignments, with or without double quotes: -bash-3.2# uname -a SunOS unknown 5.10 Generic_147148-26 i86pc i386 ...
-2 votes
0 answers
20 views

Optimize compare checksum [duplicate]

#!/bin/dash dir1="/home/lucaf/Scrivania/dir1" dir2="/home/lucaf/Scrivania/dir2" dir1_list="/home/lucaf/Scrivania/dir1list.txt" dir2_list="/home/lucaf/Scrivania/...
0 votes
2 answers
569 views

How to espace sequence of characters in sed?

I am new to regex and running into some frustrations. I am trying to work with strings that express directories and am having the issue reproducible by running: echo "a" | sed "s/a/home/...
3 votes
4 answers
5k views

Extracting text from a text file in bash

I have a large text file that is all one line. In the text are several sections that looks like foo=12345 and I need to extract them all as separate lines, ignoring the rest of the file. For example:...
1 vote
2 answers
2k views

UEFI Grub not finding config file

I need to boot Windows and two other Linux distors using Grub. So, I have installed Grub on UEFI partition with a dedicated partition for storing the files used by Grub using the following command. ...
0 votes
0 answers
56 views

Bash terminal lagging one input behind

After a recent update, I've noticed that working on any terminal for more than a few minutes causes a delay between inputting a keypress and seeing it reflected on the screen. Specifically, if I were ...
2 votes
1 answer
2k views

How print ip with iftop sorted by bandwidth usage

How I can print the list of IP addresses from iftop output sorted by bandwidth usage?
3 votes
1 answer
4k views

How to kill inactive user logins on Solaris?

On a Solaris 10 server if i do a w, I get this: 12:26pm up 85 day(s), 1:13, 6 users, load average: 0.38, 0.36, 0.38 User tty login@ idle JCPU PCPU what blah pts/1 ...
0 votes
2 answers
432 views

How to find and replace only a particular word (which is at the end of the file) using shell command?

File1: Dms 01.01.2015 feeder1 6kv close at 04:30 Updated Dms 01.01.2015 feeder1 6kv open at 06:20 Updated Dms 04.02.2015 feeder10 6kv close at 17:23 Updated Dms 04.02.2015 feeder12 6kv ...
-2 votes
4 answers
430 views

How to print last few contents in a line?

I have a file that has lines shown below, ta=/*92/*39/*1/*649/*12 ta=/*92/*12/*4/*342/*90 ta=/*92/*33/*9/*455/*3 ta=/*92/*12/*3/*649/*25 ta=/*92/*99/*7/*649/*7 and so on. I want a file that will have ...
1 vote
2 answers
2k views

How to kill python process ran by shell script when shell script dies?

I have a shell script that runs python. start.sh # Setup environment cd ~/foobar/ && \ python3 -m venv env && \ source env/bin/activate && \ pip install -q -r ...
0 votes
1 answer
63 views

How to delete a directory whose name has special characters

My ./imap directory contains two folders with names containing special characters : ‘No’$‘\351’‘.sbd’ ‘S’$‘\351’‘gol’$‘\350’‘ne.sbd’ (these are the full names with no other characters added). The ...
0 votes
2 answers
37 views

From hexdump to ascii (xxd -r stuck writing zero bytes)

To diagnose secure boot issues, I'm looking at the sbat sections of all bootloaders on a machine: sudo sh -c 'for f in /boot/efi/EFI/*/*.efi; do echo "$f"; objdump -j .sbat -s "$f" ...
0 votes
1 answer
25 views

How to suppress warnings of MongoDB shell?

I want to parse by jq output of mongo --quiet --eval "JSON.stringify(db.adminCommand('listDatabases'))" But it returns WARNING: slaveOk() is deprecated and may be removed in the next major ...
0 votes
0 answers
54 views

Does the shell provide access to all services that an OS can provide? [duplicate]

I'm an Undergraduate CS student learning about Computer Architecture and OS. Naturally, we learnt about Unix and Linux. Recently, I came across the term "shell". My understanding and ...
3 votes
2 answers
11k views

What exactly is terminal? What is shell? [duplicate]

I know about Linux terminal. I can also issue many advanced commands over terminal. But one simple concept is not clear to me. What is terminal and how does it work? I know about hardware which ...
82 votes
4 answers
63k views

$@ except the 1st argument

I need to write a shell script that runs in this way: ./myscript arg1 arg2_1 arg2_2 arg2_3 ....... arg2_# there is a for loop inside script for i in $@ However, as I know, $@ includes $1 up to $(...
21 votes
2 answers
20k 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 ...
3 votes
2 answers
2k views

how to set individual margins (left/right/top/bottom) with pandoc shell command when creating pdf?

I'm pleased to see pandoc can specify some latex (which I know almost nothing of) geometries to customize the margin size of a pdf it creates like so.... pandoc -V geometry:margin=.5in somefile.mkd --...
0 votes
1 answer
2k views

Tmux - Arrow keys return raw data/non-escaped caracters ^[[A ^[[B ^[[D ^[[C

I just updated to Debian/Linux 9 (Stretch) and am in the process of setting everything up. So far I've only installed vim and tmux. My problem is that when I use the arrow keys, they return raw data/...
41 votes
4 answers
23k views

How can I time a pipe?

I want to time a command which consists of two separate commands with one piping output to another. For example, consider the two scripts below: $ cat foo.sh #!/bin/sh sleep 4 $ cat bar.sh #!/bin/sh ...
1 vote
1 answer
653 views

difference between "ip link set" and "disconnect / reconnect" in the GUI?

I've got an Ubuntu 14.04 guest installed in virtualbox. Often when the host machine changes networks or is suspended and restarted, the guest VM loses network connectivity. I can reliably get it ...
18 votes
7 answers
16k views

Best way to swap filenames

I need to swap filenames of two files (file and file_1). I'm using the following code for it. mv file .phfile mv file_1 file mv .phfile file This works but is very buggy, It sometimes even results ...
5 votes
1 answer
5k views

All TLS requests giving Peer's certificate issuer has been marked as not trusted by the user

When I try an https request to google.com, I just recently started seeing [root@ip-172-31-47-76 ~]# curl -I -v https://google.com * Rebuilt URL to: https://google.com/ * Trying 216.58.193.78... * ...

1
2 3 4 5
243