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
0answers
15 views

Issues with my code

I am trying to recover files from my deleted file and move them back to their original location. My script is still telling me the file doesn't exist when i am writing the same exact filename. #!/...
4
votes
1answer
119 views

Shell builtin `printf` line limit?

The /usr/bin/printf util argument list length is limited to the shell's maximum command line length, (i.e. getconf ARG_MAX, on my system that'd be 2097152); example: # try using a list that's way too ...
0
votes
0answers
26 views

How to end pipe from consumer side and put producer in background

Say I have a server writing stdout to a consumer my server | upon 'some pattern' --exit=0 so basically when the consumer reads stdout, and sees a certain pattern it will exit. my question is - when ...
1
vote
1answer
33 views

How pressing tab twice listing directories and files

I'm wondering how pressing tab twice is resulting in listening all the files and directories in Linux. I'm specifically interested in where this function is defined.
0
votes
2answers
32 views

How to run next bash line even when set -e is switched [duplicate]

Say I have something like this: set -e; echo 'doing some stuff' false; status=$? post_hook send-message-elsewhere-with-status $status One way to do what I want is: set -e; echo 'doing some stuff' ( ...
0
votes
1answer
27 views

Error keeps appearing “syntax error near unexpected tokefi”

I am creating a script to restore files back to their original location after being deleted and I keep having this error pop up. Why and how to fix the issue? #!/bin/bash if [[ ! $1 ]]; then echo -...
0
votes
0answers
22 views

Determining the max RGB value (white) on a xterm-like terminal

One way to determine if a terminal is predominately dark or light is to get the value if its background color, and compare that with the grey color. However in order to do this you need to know what ...
1
vote
1answer
34 views

Linux command that continuously outputs string of text

At some point I used a shell command that continuously sent a very short string of text to the standard output, but at this moment I can't recall it's name. Its name was something very short, like '...
14
votes
2answers
983 views

How can I prevent Bash expansion from passing files starting with “-” as argument?

I'm trying to recursively search a string with grep but I get this: $ grep -r "stuff" * grep: unrecognized option '---corporate-discount.csv' Usage: grep [OPTION]... PATTERN [FILE]... Try 'grep --...
3
votes
1answer
60 views

$-expansions not performed as expected when following a redirection

It seems that bash and zsh will perform the variable and arithmetic expansions in a child process when a) they're following a redirection operator like <, >, >> or <<<. b) the ...
0
votes
0answers
37 views

bash shell modes? how to pipe request to shell on remote server

I have this tcp server in Node.js that will open a shell and pipe the request to the shell: const net = require('net'); const cp = require('child_process'); const server = net.createServer(s => { ...
0
votes
1answer
63 views

How can I open terminal and run command automatically?

I'm in the terminal emulator. I want to open another terminal to run a specified command. gnome-terminal -e "zsh -c 'pwd; zsh;'" That runs pwd and zsh consecutively and successfully in another ...
0
votes
1answer
24 views

setup.sh script under z/OS unix fails with “FSUM7332 syntax error: got (, expecting Newline”

I had an application packaged as .tar and FTP'ed it in binary to my zOS/linux directory. I untar the package with tar -xvf successfully. However when I try to run a setup.sh script for the ...
-1
votes
0answers
22 views

I have installed redhat but unable to install any application due to yum

I have installed redhat, but I am trying to install applications but red hat is not allowing it due to yum. I am not getting it. What should I do so that I can install various applications?
0
votes
2answers
40 views

Concatenate the Content of Files from Various Directories with a Blank Line in Between

I have the file dir1.txt that contains the names of the following directories: 2 3 4 Directory 2 contains files 2_1.txt and 2_2.txt Directory 3 contains files 3_1.txt and 3_2.txt Directory 4 ...
0
votes
3answers
40 views

create single string argument using heredoc or other technique

I am trying to execute a script on remote servers, passing the script as the last argument ntrs exec-all-ubuntu --exec `cat << 'EOF' echo "$(pwd)" echo "$foobar" EOF` The problem is that ...
0
votes
1answer
18 views

How to start my application after starting of “daemon” process in single script

I have a script, that starts my server. I want to start openvpn client before it. Here my current working solution: #!/bin/sh openvpn --client --config $OVPN_CONFIG & sleep 10 npm start I ...
0
votes
0answers
19 views

How to switch user in the server by su without password through shell script?

I am using cygwin to run my expect command for login into server. Once login i have to switch the user by su command writing password in the shell script which does not prompt for password and ...
12
votes
4answers
1k views

How to rename multiple files in a directory at the same time

I have directory say /var/tmp/abc which has 4 files: 12345-ram-3e3r5-io9490-89adu9.csv 45434-dam-qwe35-to9490-43adu9.csv 11234-cam-yy3r5-ro9490-85adu9.csv 14423-sam-hh3r5-uo9490-869du9.csv I want to ...
0
votes
2answers
40 views

Run ssh command without quotes

You can execute a command on a remote server using ssh user@host 'the command' but is there a way to execute the command without quotes? (I am on BSD and using OpenSSH)
28
votes
5answers
2k views

How to redirect stdout to a file, and stdout+stderr to another one?

How can I achieve cmd >> file1 2>&1 1>>file2 That is, the stdout and stderr should redirect to one file (file1) and only stdout (file2) should redirect to another (both in append ...
0
votes
1answer
34 views

how to run a bash that must be run with a specific user with another user without password

I have 2 users. test1 that i created it with /sbin/nologin and has no password. test2 that has sudo privilege and has passworsd. I have this script: /data/tempWork/fazitst that must be run under ...
0
votes
0answers
37 views

space isn't release after removal [duplicate]

I accidentally created millions of directory with my script. After I rm -rf them, there are still space occupied by my removed directories. Also there is about 2 seconds delay every time when my ls or ...
0
votes
0answers
55 views

How to make a full bash script that compares the shadow and the passwd file?

I have two files, passwd and shadow a. Sort both files b. Compare both files line by line   i. Match on user name output to third file   ii. If it doesn’t match, output to fourth file   iii. ...
2
votes
1answer
94 views

Replace all items that are not belong to characters and numbers by ' '

I want to replace all symbols like '.','-','/' and so on by ' ' I triedsed 's/[[!:alnum:]]/ /g' example.txt but it does not work and for sed 's/[,;\.\-\/()_]/ /g' example.txt, I found that I cannot ...
1
vote
1answer
43 views

Using sed within a makefile

I want to modify the cygwin path to the windows path from within a makefile. For that purpose, I am using CURDIR := `pwd` WINDIR := $(shell echo $(CURDIR) | sed -e "s/\/cygdrive\/\(.\)/\1:/" | sed -e ...
0
votes
0answers
16 views

Display format of ls [duplicate]

When listing the files in a directory by running ls I see a sort of tabular format, with lines and columns. If I pipe this output into head, wc or any other program, it seems to interpret each file ...
4
votes
1answer
233 views

Run script for 10 times or until it meets the condition

I have following shell script. OUTPUT=$(systemctl is-active etcd) if [[ $OUTPUT == active ]]; then echo "The result is successfull" else echo "The result is unsuccessfull" fi I ...
-1
votes
1answer
24 views

How can I pass an argument in a shell script without quotes?

I have to make my own command shell where a bash script calls the shell executable and does so with quotes. The problem is that when I try to do so with logical operators it seems that the quotes turn ...
-2
votes
1answer
44 views

Does execvp() account for logical operators?

In my class assignment I'm supposed to make my own command shell. In the shell, I am supposed to have it take various command line arguments including logical operators such as && and ||. I ...
-2
votes
0answers
25 views

use SSHPASS to connect to multiple servers with different credentials

I want to create a FOR loop and use SSHPASS. SSHPASS will try to connect to a server using Credential A, if that doesn't works it should use Credential B and so on. Once it gets connected successfully,...
-1
votes
1answer
27 views

How can I run only a portion of a command line in a user built shell?

I make a shell that takes arguments in a command line with special conditions on what it is able to do. For example, anything that appears after the # character will be considered as a comment and ...
-1
votes
1answer
24 views

why does test command startswith fail (exit with 1)?

I have this test command: test "ssh://hg@bitbucket.org/teros/moodwire_demo" == ssh*; echo $? why does it exit with 1? I am trying to see if the first string starts with the second string.
0
votes
0answers
18 views

xupnpd2 mediaserver filter log-messages

I use the xupnpd2 media server (https://github.com/clark15b/xupnpd2) on the router to stream a few HLS streams to the TV. The software would have to be extended by HTTPS and the HLS processing adapted ...
4
votes
1answer
199 views

stdout and stderr redirection to different files

How can I redirect stdout to 2 different files and stderr to another, different file? I want something like <my_cmd> 1> file1 file2 2>file3 I know: <my_cmd> | tee file1 file2 > /...
0
votes
1answer
20 views

Logging all crontab output using MAILTO

I've been trying to get all cron job outputs to a file (not email). The alias is set in /etc/aliases. logthecron: "|cronlog.sh" And in crontab MAILTO=logthecron. The cronlog.sh file writes to ...
0
votes
4answers
47 views

Find name of directories that don't contains specific subdirectories

I have several directories like so : Rep1/foo/bar/files Rep2/foo/otter/files Rep3/foo/bar/files ... What i'd like to have is the name of the directories that doesn't have the subdirectory */bar/ ...
2
votes
1answer
34 views

Why I have to not quote a string variable in this specific case?

My Ubuntu/Debian-based Linux update POSIX shell script seems to require me not to double quote the string variable with the stored command, which is being executed. As I don't understand this issue, I'...
1
vote
1answer
20 views

If condition on shell not working , not sure what is the mistake I am doing? [duplicate]

I have a requirement to perform specific set of tasks based on server , So I want to have the condition(s) defined based on server. Here is the script I came up with and I have read multiple blogs and ...
0
votes
0answers
26 views

Nesting back-ticked commands [duplicate]

I have this which won't work: source_dir=`cd `dirname `readlink "$BASH_SOURCE"`` && pwd`; what does work is this tho: source_dir=$(cd $(dirname $(readlink "$BASH_SOURCE")) && pwd); ...
0
votes
0answers
22 views

Why does single quotes around arguments fail to prevent “syntax error near unexpected token '('”? [duplicate]

I read that surrounding command line arguments with single quotes is necessary when the command line argument is a string that contains parentheses. However using single quotes around the following ...
1
vote
1answer
45 views

Automatically print number of lines of command line output

In my fish shell, I am using fish command timer to automatically show the duration of each command after it has been executed. This is a neat feature, which I recommend. Now I want something similar ...
0
votes
1answer
32 views

How to send stdin to while loop using redirection operator

Not sure if I used the right words in the title, I am trying to do this: while read line; do echo "$line" exit; done; <( echo "foo\n"; exit ) but it hangs, I don't think the while loop ...
-1
votes
1answer
33 views

compare strings in sh [closed]

Here is what I tried: #! /bin/sh if [ -z "${ENCRYPT_ALL_PWD}" ]; then if [ ! -z $SA_USER ]; then DBAUSER=$SA_USER $ECHO "Yahoo!!!!!!!!!!!!" else ...
1
vote
1answer
42 views

how to avoid mounting directories with overcomplicated paths?

Background: I am accessing a remote directory like this: smb://serv.erNa.me/storage/directory/ Accessing it, is not an issue. Through the file manager I copy paste the path, press Enter, insert ...
0
votes
2answers
53 views

Split chained commands into commands

Is there a command that takes as input another command (which may or may not include the control operators &&, ||, ; and possibly others that might be relevant) and breaks the command into its ...
-1
votes
1answer
61 views

Bash script, error “Arg list too long”

I need to run a bash script in a .lua file: os.execute ("/path/to/file.sh") file.sh: #!/bin/bash route add 149.36.98.78 reject The permissions for file.sh is [-rwxr-x---] root www-data I'm ...
1
vote
2answers
35 views

Why can't tcsh do a single-line 'which -> vim' command?

I often have to do which command, and then open it in vim to actually see what's inside. I'd like to have an alias or function that does this, with tab completion. Here's what I've tried: superwhich()...
0
votes
1answer
23 views

How to insert text in a file after particular pattern in shell script?

I have to insert some text after matching a pattern in between a line. core: [dev][delta3=deltafile;delta3dir=755|workpm][staging=stageingfile] Expected output is: core: [dev][delta3=...
0
votes
2answers
51 views

How to write a script to indent lines in the input files depending on how deep the brackets are nested? [closed]

The parameters to the script are an indentation character c and a number of characters per level n, these parameters are followed by a list of files (if no files are provided, standard input is used). ...