Stack Exchange Network

Stack Exchange network consists of 175 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.net before posting here.

0
votes
1answer
12 views

Konsole does not run shell specified in /etc/passwd

I've been using Bash for a long time on Fedora with Gnome, and recently switched to Arch Linux, Plasma and ZSH. I set up zsh, file, used chsh -s $(which zsh), and it works. However, every time I run ...
1
vote
1answer
30 views

Root shell in system filesystem with GRUB

I'm learning about GRUB and, after search for a while, I tried to get a root shell changing the kernel load string: /boot/vmlinuz-4.9.0-8amd64 root=UUID=e8485edc.... ro single to /boot/vmlinuz-4.9....
0
votes
2answers
20 views

Looping through a file with two columns and reading those two columns

I have a txt files with all the file names I need to analyze. I have this file (inputFile.txt) : /path/file1a path/file1b /path/file2a path/file2b i have a code which needs two two input files in ...
0
votes
2answers
33 views

new line not append instead append on the end of the line

we gave the following config file ( config.txt ) more config.txt export var1=345476746 but when I am appending new parameter as echo "export var2=5645" >> config.txt we get more config.txt ...
0
votes
1answer
67 views

difference between echo ($x) and a=“($x)”; echo $a

When I execute the following in terminal: x=1 a=($x) echo $a #output: 1 echo ($x) #output: -bash: syntax error near unexpected token `$x' Why are above outputs different? Also why are the ...
1
vote
1answer
27 views

bash + write standard output and error to both logs

in my bash script I use the following approach in order to write every thing from standard output and standard error to log.txt export LOG=/tmp/installation/log.txt exec > $LOG 2>&1 so ...
0
votes
2answers
43 views

How to run a command with a different working directory?

I use this shell pipeline to get a SQL dump using the terminal: $ cd var/lib/mysql && mysqldump -uroot -p"craft" --add-drop-table craft > ~/../docker-entrypoint-initdb.d/base.sql &&...
4
votes
2answers
159 views

pipe commands inside find -exec?

Let's suppose I want to find all .txt files and search for some string. I would do: find ./ -type f -name "*.txt" -exec egrep -iH 'something' '{}' \; What if I want to do a more complex filtering, ...
-1
votes
0answers
40 views

What is the “fsed” command used for? [on hold]

I have to execute a script locally on my Laptop which runs a Fedora 29. The script contains several references to the fsed command: fsed 's/get.drivers//' ../scripts/hudson/launch.sh However I ...
11
votes
2answers
1k views

Exit shell with shortcut (not typing exit) that closes session properly

I use a ProxyJump command for a number of ssh sessions I use daily, and also switch users a lot on these sessions and having to type exit 3 or 4 times in a row isn't too fun. I am aware of newline + ~...
0
votes
0answers
55 views

SSH works but not SFTP

I am working on a project for a client from which we are using multiple docker containers on a host machine. I need to copy some files from my computer to the host machine, but when using an SFTP-...
2
votes
1answer
58 views

How to differentiate an executable sh file, and a source sh file?

I have sh files that are executable, and others that are only meant to be sourced by executable ones. On the executable ones I use no extension at all, and have the first line as #! /bin/sh. On the ...
-8
votes
2answers
72 views

Error Shell Programming in Linux [on hold]

I need to fix my code? i=0; bil_genap=0; bil_ganjil=0; echo -n "Batas loop : "; read batas; if [ -z $batas ] | [ $batas -lt 0 ]; then echo "Ops, tidak boleh kosong atau Batas loop ...
0
votes
2answers
41 views

Change value inside xml attribute using sed?

I have the following attribute: <client-version>1.2.8</client-version> How can I replace everything inside <client-version></client-version> to only change the value (1.2.8)? ...
0
votes
0answers
9 views

Update an existing SFV file using CFV

I have an existing sfv file generated using cfv -C -tsfv -rr Now how would I update this file when there are new files added to the directory? Re-generating the whole thing will take a long time (an ...
0
votes
1answer
38 views

Linux Shell - How to remove escape characters generated by JQ when json is read with sed?

I am trying to read a json file and use its output in jq to build another json, combining so said json file and other values, and pass it to CURL I read the file with policies=$( sed 's/\\//g' ...
2
votes
1answer
28 views

Execute python file from shell script based on the cat/awk output

I'm executing a python file based on the output from the cat/awk output. Say I have a file something like samp.txt: test.py test.conf dev.py dev.conf Now I have a small shell script, which cats ...
1
vote
1answer
26 views

understanding backslash in POSIX standard

I've seen interesting video about POSIX standard on youtube. It was part of lecture, asking if anyone knows the result of echo \\\\\\ in bash, and sh(POSIX standard?) sh-3.2$ echo \\\\\\ \\ bash$...
0
votes
1answer
33 views

Count per second on the log file

I have messages log file each line represents a cdr or transaction and that looks like: 2019-03-14 13:58:16,260 DEBUG xxxxxxxxxxxxxxxxxxxxxxxxx i have to calculate transactions per second. which ...
0
votes
1answer
28 views

shell linux unix xargs -i replace string

I have hard time understanding the xargs part of this command : find -type f | sed 's/ /\\ /g' | xargs -ifil file fil | \ grep ELF | grep executable | cut -d: -f1 | xargs -ifil find fil -exec ...
0
votes
0answers
16 views

Change mode of files created by root

I have a docker container which has volume (shared folder) with my Linux machine and docker Linux (alpine) container. Sometimes I have issue with file permissions when I create file in docker ...
-1
votes
0answers
19 views

How to convert a byte stream into a useable path

Assume one has a \n in a directory name and one cd's into that directory. How can one alter the following commands so that the final ls will always work? pwd | od -A n -t x1 --width=255 | tr -d '\n' ...
0
votes
2answers
53 views

Is there any way to know how many sockets have been created by a C program?

I have been running a C program which connects to a Redis database every once in a while. After running the program for a few hours it was displaying "Cannot create socket: too many files open". I'm ...
1
vote
1answer
35 views

/bin/sh symbolic link not working properly

I am using i3, and by default, it uses sh when starting process with the i3 config exec command. This is fine and dandy, but that means the environmental variables created in my .zshrc do not get ...
0
votes
0answers
36 views

Working with strange filenames [duplicate]

How can the script below be made to always work no matter the filenames returned by find ? #!/bin/sh cmds_should_always_work() { echo "\n\n*********************************" $1 stat --...
0
votes
0answers
24 views

escape certain characters in a shell variable [duplicate]

I have a shell variable which will be used within the replacement string of a sed regex. Therefore, all characters &, / and \ need to be escaped by a preceeding \. I managed to do it for & ...
1
vote
2answers
39 views

Expanding only certain variables inside a heredoc

This is an extension of the question I asked . Passing directory from command line to shell script I have a script which writes another script using a heredoc. I need to be able to write unexpanded ...
0
votes
0answers
17 views

Passing directory from command line to shell script [duplicate]

I want to pass directory as a command line argument to the shell script. #!/bin/bash sourcedir=/home/dir/data cd $sourcedir find "$PWD" -maxdepth 2 -name \*_R1*.fastq.gz > list1 fastq_list=$...
1
vote
1answer
30 views

shellcheck: “In POSIX sh, ulimit -H is not supported”

I am using shellcheck to fix warnings in a sh script. The script checks for the hard fd limit with: ulimit -H -n It sets the soft fd limit with: ulimit -n "$MAX_FD" This generates the shellcheck ...
2
votes
1answer
306 views

Who is eating data? Xargs?

I am trying to parse a recursive directory of PHP files using the built in PHP linter, which works like this: $ php -l good.php No syntax errors detected in good.php $ php -l bad.php PHP Parse error:...
1
vote
3answers
51 views

Sed add newline before last occurrence of brace?

I want to insert a new line before the last occurrence of brace. My text file looks like that "accounts": { "0x0000000000000000000000000000000000000008": { "builtin": { "name": "...
2
votes
2answers
47 views

Use of multiple <<<

I am wondering about the way the redirection <<< works in bash. I understand that it redirects the chain after it to the command before as if the content was in virtual file. Examples $ ...
-3
votes
1answer
42 views

Prevent user from creating and deleting user account from his login [closed]

I want to create a non root user and is there any way/command if we can disable only two commands(useradd and userdel) for any particular user. we don't want user to create and delete any user on the ...
0
votes
0answers
28 views

SFTP upload directories and files to a VM

I have 2 directories and 4 files drwxr-xr-x 8 root root 4096 Jun 30 2018 apache2 <<< 📁 drwx------ 2 root root 4096 Jan 23 19:40 .ssh <<< 📁 drwx------ 10 root root 4096 Mar 12 ...
0
votes
2answers
41 views

Looping without brace expansion

I'm using a blackbox CLI based on Bash and I'm not entirely sure what stuff I can use. Brace expansion doesn't work, and with it goes my ability to do loops without listing the arguments explicitly, ...
1
vote
2answers
47 views

mv : get info from files to be overwritten

Is there any "super" mv command out there which displays files info (size, date, etc.) when a destination file is to be overwritten with a source one ? This is, when moving files around and two files ...
0
votes
1answer
76 views

Can I improve this code?

I'm wondering if this could be improved or cleaned up at all. The idea is the user selects one of the three categories then makes a note on that selection. Then the note is appended and saved to the ...
1
vote
1answer
36 views

Remove a list of files over SSH

I'm trying to do the following: Retrieve a list of remote files matching a glob pattern: existing_files=$(ssh user@example.com "ls pattern*") Add a new file that matches the pattern: scp ...
0
votes
0answers
31 views

Give root's permission to restricted user using PAM and Linux capabilities

I want to give root's permission (or root account) to my test's user not using wheel-group or sudoers on CentOS 7. Instead I would like to use module pam_cap.so and linux capabilities. I try this: ...
2
votes
1answer
33 views

How to use character classes

In one of my systems, when I run ls [:lower:]*, it will list all files that start with a lowercase letter. In another one, it will give an error: ls: cannot access [:lower:]*: No such file or ...
0
votes
0answers
23 views

Execute CMD command with Shell [migrated]

Trying to execute a .bat file from a shell script. This .bat file calls another .bat file. The first bat file contains: other_file.bat -c some_conf.xml This means I cannot do: start dir/my_file ...
0
votes
0answers
11 views

Ubuntu multiple terminal shell configuration [duplicate]

How to allocate different shell to different terminal emulator? Ex : for terminator terminal allocate /bin/zsh shell and for gnome-terminal /bin/bash shell.
1
vote
1answer
18 views

Can a subshell fetch an argument within the parent shell scope?

I want to run different versions of a utility onto the same data like so: current_dir$ (cd my_utility_version_dir && exec ./my_util my_data_file) Is there a way for my_util to look for ...
0
votes
0answers
15 views

How to track a file for processes that use this file

I have a script, that listens for file /lib/modules/4.10.0-19-generic/kernel/drivers/media/usb/uvc/uvcvideo.ko and if the file is been accessed then runs the lsof command: #!/bin/sh inotifywait -mrq -...
1
vote
2answers
41 views

Bash environment variables in non interactive mode

I'm trying to define environment variable for non-interactive console in Raspbian. In theory I need to add the varaibles to ~/.bashrc or ~/.profile or /etc/bash.bashrc or /etc/profile. For example I ...
1
vote
1answer
40 views

“bash: /usr/bin/ls: Permission denied” Arch linux

Today I discovered that the command ls to list files, only returns the error: bash: /usr/bin/ls: Permission denied This happens for every directory I try and also when running the command as root. ...
0
votes
1answer
23 views

Bash script to link networked account directories to local account directories

I'm working on a script that will create a local user account, and link local account directories to networked account directories. The only directories I would like to be created and linked are the ...
0
votes
2answers
38 views

How to split a string argument in a bash over multiple lines without adding space

I'm running the following command: some_command --flag "foo\ bar\ quux" arg2 This causes the string to be passed as foo\tbar\tquux. I'm looking for a way to have this argument passed ...
0
votes
2answers
39 views

Append string on redirect

When redirecting all output to stderr: stat file >&2 ... if the command throws an error (e.g. file does not exist) how can one prepend some arbitrary text, such as: <<MY ARBITRARY TEXT&...
0
votes
1answer
36 views

Total Progress over entire bash shell script

EDIT FOR CLARITY : say I have the following script (let's posit pv and curl are already installed) : (that currently runs under ubuntu but that I plan to make POSIX-compliant so that it may run on ...