Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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....

0
votes
1answer
10 views

Comparing the `time_total` of two curl requests to different sites

I know that I can get the time_total of of curl request by using this command: curl https://www.google.com -s -o /dev/null -w "%{time_total}\n" Is there any way for me to easily compare the results ...
1
vote
1answer
30 views

Get container directory more easily

I have a bash script here: $GOPATH/ src/ build.sh and in build.sh I have: export GOPATH="$(cd $(dirname "$BASH_SOURCE") && pwd)" is there a shorter way to get the containing dir ...
-1
votes
4answers
78 views

How to remove leading and trailing spaces from a shell variable [on hold]

I have variable named tablename and it has leading and trailing spaces (for example, tablename= yyy ). I want to remove the leading and trailing spaces (OUTPUT : tablename=yyy ) and write this ...
1
vote
2answers
33 views

Pick out a date from a command response

I have a command response that looks something like that: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXX | XXX | Thu Oct 18 03:32:00 UTC 2018 XXX | ...
0
votes
0answers
9 views

Start interactive bash session with custom config without saving it as a file

I have a string variable that I want to use as a bash rc file (contains aliases and shopt commands), and start a new bash session as a different user. Something like this: sudo su - myuser --session-...
6
votes
5answers
826 views

Making summary of sentences

I have data and I want to summarize sentences to generate conclusions. The example below is not related to the data, but just to clarify the idea so I can replicate it. Employee Suzie signed one time....
10
votes
2answers
1k views

Can you explain these three things in this bash code for me please?

I have a function in my .bashrc file and I can't wrap my head around it. I know what it does, it steps up X many directories with cd Here it is: up() { local d="" limit=$1 for ((i=1 ; i &...
2
votes
0answers
43 views

Difference between closing terminal and closing shell on child processes

Opening a new terminal and typing the command firefox& inside, ps -l gives : 4 R 1000 23132 23104 99 80 0 - 2177945 - pts/27 00:00:07 firefox If the shell is closed with the command ...
0
votes
2answers
58 views

Is there something similar or like “pass” in python in bash/shell programming?

I sometimes need a command like pass in Python in my bash scripts. Like: if grep something then pass else code fi In Python you have: >>> for element in a: ... if not element: ...
-3
votes
0answers
32 views

Shell script but don't know how to use [on hold]

When my pc boots, it shows up a strange screen with command line shell> I don't know what it is, since I am newbie to Linux. I tried to use "ls", but nothing shows up.
1
vote
2answers
88 views

How do I use shell commands with a directory that contains '-' like '-78059735'? [duplicate]

I have an external program that generates directories with strings that are negative integers. I am trying to use basic shell commands including cd and ls with this directory, for example: cd -...
0
votes
1answer
18 views

copy numerous files/folders in linux with queuing and the ability to break and continue

I'm copying terabytes worth of data from an OLD OLD OLD *nix system. I could spend the money to buy new hardware to plug the drives into but I want to avoid spending money. The system is crappy. It ...
0
votes
1answer
29 views

How to pass multiple parameters to su <USER> -c “command”

I want to execute composer as non root user. So I renamed main composer executable file to composer-call and then create another executable file called composer. #composer.sh su nginx -c "composer-...
3
votes
2answers
38 views

How to use fish on remote servers that have it installed without changing login shell?

I regularly ssh on several different servers, some of which don't have fish installed, but many do. I'd like to get fish as shell if available (changing midway is always tedious, and you lose the ...
13
votes
2answers
557 views

What prevents stdout/stderr from interleaving?

Say I run some processes: #!/usr/bin/env bash foo & bar & baz & wait; I run the above script like so: foobarbaz | cat as far as I can tell, when any of the processes write to stdout/...
1
vote
3answers
45 views

How can check ipv4 address in shell. Like is it *.*.1.* or *.*.0.*?

So here I tried to get from the ifconfig file, but same with errors with simple ifconfig command !#/bin/sh if [/home/pi/ifconfig | grep -Eo ‘inet (addr:)?([0-9]*\.){3}[0-9]*’ | grep -Eo ‘([0-9]*\.){3}...
1
vote
1answer
26 views

How to log myself out of ssh, from a bash script?

Connected to a remote server via SSH. On occasion, I run a specific bash script. When certain conditions are met (it's work completed successfully), I wish to be automatically logged out of the SSH ...
4
votes
2answers
213 views

Makefile and .ONESHELL

When .ONESHELL is not used Makefile executes each shell commands in a separate shell. What is the benefit of this? Why doesn't makefile uses the same shell?
0
votes
3answers
33 views

Extract a string out of key, value from a text file, and assign to a new variable

Need a script to iterate through below file to read keys, values and extract values eg. foo_key1, foo.com, /tmp/worker${Build_Number} out of key and values assign them to another variable (eg. A="...
-1
votes
2answers
43 views

CD vs Full Path per command

What is faster or considered better practice in shell scripts to first Cd into a directory then carry out commands or to write the full path? For example: Is it better to write cd /directory1/ and ...
0
votes
3answers
53 views

How to make tail to automatically reconnect to a log file that was deleted and recreated together with its parent directory

I am using tail with option --follow=name to watch my log files in my servicemix instance (path = ${smx_home}/data/log/servicemix.log). ServiceMix have a 'nice' feature to restart clean with ...
0
votes
1answer
69 views

Shell script error to extract file data

I have attempted to write a shell script and it is giving an error which I cannot understand. The script goes like this: #!/bin/bash while read id do cat demuxR1/$id.barcode.in.R1.R1.fastq demuxR2/$...
0
votes
0answers
15 views

How to modify bash completion for command names to match custom list only?

I want to customize bash completion on command names, such that matches are looked for in a particular list only. If I try the following: complete -E -W "foo bar" it works fine on an empty line, ...
0
votes
1answer
21 views

What is the difference between calling “id -G” and “id -G -r”?

I know the -r flag should print the real group the user is in. But since -G already prints all his groups, does this make a difference? What does id -gr xxxsome_user really print out? How can a user ...
4
votes
1answer
65 views

Pass variable to spawn [duplicate]

I want to pass server name which is listed in a file (servers_list) as variable to spawn command which is in another script (user_create_script). Purpose of this script is to create user(david) in ...
1
vote
1answer
48 views

xargs plus shell string manipulation vs sed [duplicate]

I am trying to summarise the file extensions in a directory recursively. find .| xargs -d "\n" -I@ echo "${@##.*}" | sort |uniq -c But this is giving me a series of blank lines. Not what I wanted. ...
1
vote
0answers
24 views

Shell script to assign variable to an environment variable specified in command line argument? [duplicate]

I have this script that assigns name of the second argument to the environment variable that is specified in first command line argument. FOr example: ./adden.sh PATH /test/abc will add /test/abc to $...
1
vote
0answers
14 views

Mounted CIFS directory by web shell not visible in the system shell

I use PHP shell_exec to run the command echo password | sudo -S mount.cifs //192.168.1.15/Share /share -o username=root,password=password HTTPD user is granted sudo-pivilege, the command ran ...
1
vote
1answer
23 views

edit names in phylogenetic tree in newick format [closed]

I have a phylogenetic tree in newick format, and I would like to remove some fragments of the name of the taxa, 1_[genus_specie_1]_characters:0.2654682758,(((((((((((((((2_[genus_specie_2]...
1
vote
1answer
28 views

local vs non-local chsh

How do I get chsh in Amazon EC2 (Linux 2)? $ chsh -s /bin/zsh zsh: command not found: chsh Here's what I see: $ ls -ahl /usr/bin/ | grep chsh -rwxr-xr-x 1 root root 16K Jul 27 21:02 lchsh ...
1
vote
1answer
12 views

setting a remote stdout into local KORNSHELL variable

I'm writing a script that others here on Unix & Linux have been graciously assisting me on. The idea is to compare MD5 checksums between a local file and a remote one. The local file checksum is ...
0
votes
1answer
14 views

KDE SC 5.10.5 on Kubuntu 17.10 / After logging in, user has only primary group assigned

Some time ago (can't tell exactly when, but it's been one week at least), users logging into KDE on this system stopped being assigned membership to their supplementary groups. For example, user "...
0
votes
3answers
46 views

Exit from script if SSH prompts for password [duplicate]

I am trying to achieve a scenario where I need to SSH to ABC server from XYZ server. Public keys will set up already to smooth password less login. Now i just want to exit from script if found that ...
0
votes
3answers
44 views

adding a new line character to a row

I'd like to extract the 2nd field and transpose it to become a row cat > temp1 1 73 2 74 3 75 My approach : cut -f2 temp1 | tr '\n' '\t' > temp2 The result : temp2 73 74 75 ...
1
vote
5answers
46 views

add file name as header of column

I have a directory with tables in txt format, and I'd like to add the file name as the header of the second column, for example: file_1.txt row_1 1 row_2 0 row_3 1 row_4 1 row_5 1 row_6 1 ...
0
votes
4answers
32 views

get output of this command from another server via ssh

I'm trying to ssh into a server and get the system uptime using a specific command but it's failing to execute. this would work locally on almost all unix systems startuptime=`uptime | awk '{print $...
3
votes
3answers
113 views

How to `paste` stdin next to stderr?

Usually paste prints two named (or equivalent) files in adjacent columns like this: paste <(printf '%s\n' a b) <(seq 2) Output: a 1 b 2 But when the two files are /dev/stdin and /dev/...
1
vote
0answers
45 views

How to get linux shell script command containing quote working in crontab?

I see an Issue, where shell script command/script works fine when ran through command line or shell script but fails when triggered through crontab. Following are details of the command Command run ...
1
vote
0answers
11 views

Using different formats for export in .bashrc [duplicate]

When I check my ~/.bashrc files then sometimes I see entries like export LS_COLORS="di=01;94" and sometimes I see LS_COLORS="di=01;94" ; export LS_COLORS Is there any difference between these two ...
1
vote
1answer
22 views

Basic openssl encryption script issues

I'm currently working through a series of exercises in an attempt to improve my bash scripting knowledge. The exercise I am working on is as follows: Write a script called encrypt.sh that's used to ...
0
votes
0answers
28 views

Bash script delete all folders except [duplicate]

I'm trying to delete all folders in the current directory except node_modules, however, it runs and does nothing. My script: sudo rm -rf !\(node_modules\)
0
votes
1answer
31 views

What's the purpose of having “env [shell]” as an interpreter? [duplicate]

I already stumbled over #!/usr/bin/env bash on numerous occasions and never questioned it. Now, I'm wondering what the purpose of wrapping the shell interpreter in an env command, i.e. why not just ...
-3
votes
1answer
125 views

Why exit status of command “ls” is difference between bash and csh shell?

Why exit status is different between bash and csh shell?, In ls man: Exit status: 0 if OK, 1 if minor problems (e.g., cannot access subdirectory), 2 if serious ...
0
votes
4answers
44 views

replace all non alphanumerics with underscore

I have this: second_arg="${second_arg/[^[:alnum:]]/_}" if I do this: second_arg="foo::" second_arg="${second_arg/[^[:alnum:]]/_}" echo "$second_arg" then I get: foo_: how do I replace all ...
5
votes
4answers
683 views

How do I display file names that contain two characters and one of them is c?

I tried doing ls [a-z][a-z], but it doesn't seem to be working.
-1
votes
2answers
50 views

grep file for pattern without dot/extension and delete both with next line if empty [closed]

I have a file containg data like this: https://pastebin.com/TXrmVpwF What I am trying to achieve is to find and remove all lines having pattern but not having extension or dot in name and if true ...
0
votes
2answers
39 views

Add leading zeroes to first column

I'm looking to add four leading zeroes to the first column of a csv file so this: EADUnitID,irn,EADPhysicalTechnical,AdmPublishWebNoPassword,AdmPublishWebPassword,EADUnitTitle,EADBiographyOrHistory,...
1
vote
0answers
17 views

source activation of R-Env works on commandline but not in .sh script

When I run . deactivate . activate R-Env or source deactivate source activate R-Env from the command line I have no issues. However when I run the same commands in a .sh script I get the ...
2
votes
1answer
31 views

Start shell with tmux and attach only to a session if it is unattached

I am currently starting tmux when opening my shell, which the following config for my shell [[ $TMUX == "" ]] && tmux new-session Is there any way to start my shell and attach tmux to the (...
0
votes
2answers
51 views

Can't remove space from beginning of variable

I am trying to crate a folder with the label and uuid of a media device plugged in as its name, on another flash drive which I am using to log. I have the following code: LOGDEVICELABEL=...