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
-2 votes
2 answers
29 views

bash: /etc/environment: Permission denied

I am trying to run following command: grep -q NDDSHOME /etc/environment || echo 'NDDSHOME="/opt/rti_connext_dds-6.0.1"' >> /etc/environment But facing permission denied error: bash: /...
0 votes
1 answer
69 views

How to `sudo cat` the contents of a symlink

I have created a symlink foo to the file /bar/baz using $ ln -s /bar/baz foo $ ls foo Here /bar/baz is a log file that only root has read permissions for. Now I would like to print the contents of /...
0 votes
1 answer
39 views

Line up text based on line contents

Is it possible to insert new lines in order to line up the contents of a file? I have: 1:1 Lorem ipsum dolor sit amet consectetur 1:1 This is sample text of varying length. adipiscing ...
0 votes
1 answer
15 views

Merge multiple files and format output into columns with line wrap

I'm trying to show multiple files to a user within less. These files have relatively long lines and contain the same text but in different languages (differences in line length to be expected). ...
47 votes
2 answers
20k views

How to disable "auto cd" in zsh with oh-my-zsh

Googling this didn't show up any results. Here's what I mean: I have a binary file named x in my path (not the current folder, but it is in the PATH), and also a folder with the same name in the ...
2 votes
2 answers
99 views

Fish shell reports "math: Error: Missing operator" on tab completion

I noticed the error this morning, but I don't think I have changed anything last night, so I am very confused right now. Perhaps I updated some utilities on my system and it somehow broke the back ...
12 votes
3 answers
43k views

Passing arguments with quotes and doublequotes to bash script

At this moment I have: #!/bin/bash screen -p 'ScreenName' -x eval 'stuff '"'"$@"'"'\015' echo eval 'stuff '"'"$@"'"'\015' But when I call my script as: # script.sh asd "asd" 'asd' my arguments ...
0 votes
1 answer
128 views

How to treat a symbolic link as a file itself (instead of the one it points to)?

Out of curiosity i wanted to open a symlink as itself instead of the file it points to, just to see how it looks like. While there are ways to see what file it points to like using readlink and ways ...
2 votes
0 answers
64 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|--...
62 votes
16 answers
262k views

Removing a directory from PATH

I'm trying to compile wxWidgets using MingW, and I have cygwin in my path, which seems to conflict. So I would like to remove /d/Programme/cygwin/bin from the PATH variable and I wonder if there is ...
1 vote
2 answers
379 views

What is the difference between `ash` and `sh` shell on Linux?

I am new to a lot of tools on Linux. A quick search did not help, I only got more about bash or sh, and searching for it somehow leans towards bash in the search results. There are quite a few ...
0 votes
0 answers
21 views

Netcat dont open shell outside of lan

I am trying to connect remotely my computer which executes ngrok server. I'm outside of home and I need to connect my host for get back some files. In order to fullfill this task, I used the command: ...
0 votes
1 answer
50 views

Writing a shell script to undo the changes done to the system by running a script

Question: Should I even write a script to undo the changes done by running a script in the first place? If no, then how do I clean up/undo the changes done to the system so that I can run the script ...
4 votes
1 answer
182 views

Find directories with name, but filter them if they contain a specific top-level file in them

I want to find all directories that are named Contents and then from the list of found results, I want to filter them and only include those that have a file named Database.json directly inside them. ...
0 votes
1 answer
2k views

Getting error syntax error: 'if' unmatched while executing bash script

I wanted to create a bash script to achieve a particular task although i have no knowledge of bash. Lazily asking it here directly wouldn't have have explained my question well , so i just kept ...
17 votes
5 answers
54k views

Execute a shell command upon a click event in a web page

Is there a way to execute a bash command when I click on a text in a browser? The web page is on computer A, the browser is on computer B : I want to execute the code on computer B, e.g hsetroot to ...
0 votes
2 answers
25 views

File content from env var

I would like to completely avoid writing credentials to disk. I want the credentials to be read from the environment variable. But some scripts require a credential file on disk from which they read ...
1 vote
2 answers
2k views

VNC/SSH: How to execute a command after logging in?

I'm looking for a way to create a VNC console user that executes the command screen or bash immediately after logging in so they get their own restricted shell for executing commands etc. Screen/bash ...
-1 votes
0 answers
20 views

How to use sed with a path saved in a variable

I programmed a small application for which I want to provide some kind of install script. Part of that script is to register the app as a systemd service for which I need to provide the path to the ...
6 votes
6 answers
2k views

Getting the pid's of a program line by line

I can find the pid's of my program instances by issuing command like this: pidof avconv Which is giving me results 16616 16283 16279 16198 16175 16035 15073 14049 4922 But how can I output the ...
0 votes
0 answers
12 views

I need to create different users on a CentOS 8.4 machine and one of them uses the sh shell

I know that to change the shell when creating users, I have to add the -s option, should I use /bin/sh or /usr/bin/sh? Why?
2 votes
2 answers
9k views

FreeBSD: How to set Bash as the default shell

I've used bash shell in all my Linuxes and in Mac OS X. I understand that tcsh is the default shell in FreeBSD. If I were to install bash, how would I make it my default shell?
32 votes
3 answers
3k views

Execute a readline function without keybinding?

I was just reading the readline man-page and discovered a bunch of great commands I didn't know about. However, several don't have default key bindings. Is there a way to execute the unbound commands ...
3 votes
1 answer
2k views

Read output in `screen` from outside

Suppose I opened up a screen to run some program that outouts some result. Once the program finishes, is there a way to get the result in the screen from outside. For example: I opened up a screen ...
102 votes
9 answers
50k views

Can't indent heredoc to match code block's indentation

If there's a "First World Problems" for scripting, this would be it. I have the following code in a script I'm updating: if [ $diffLines -eq 1 ]; then dateLastChanged=$(stat --format '%y' /....
2 votes
3 answers
1k views

The equivalent of cmd "for" in bash?

I only know little about bash (or any Linux shell - but I just use bash). I'm used to using for %c in (*.*) do {something} in cmd in Windows, and I really feel inconvenient without it. I tried wine ...
1 vote
4 answers
67 views

Given a weekday name, week of a month, and a year, how to find the date

I can find the last Monday using date -d 'last-monday' +%F but given a weekday name, week of a month, and a year, how to find the date? e.g. given: Monday, Week 4, June, 2022 output: 2022-06-20 given: ...
121 votes
3 answers
331k views

grep on a variable

Let's say I have a variable line="This is where we select from a table." now I want to grep how many times does select occur in the sentence. grep -ci "select" $line I tried that, but it did not ...
5 votes
3 answers
1k views

When exactly would you use ".[^.]*" or ".??*" glob patterns?

I'm trying to understand Linux, its command-line and this quote: You can run into problems with globs because .* matches . and .. (the current and parent directories).  You may wish to use a pattern ...
1 vote
1 answer
34 views

format to columns for real-time data (pipe)

Is there a way to do column-like filtering on data comming through a pipe? I am looking for a way how to do a similar thing that column -t does, but without waiting for the input to end so it would ...
0 votes
1 answer
3k views

Use a script for a telnet session

I have a problem with my script. It seems my password is wrong. #!/usr/bin/expect set ip [lindex $argv 0] spawn telnet $ip set timeout 10 expect "Login:" send "administrator\r" expect "Password:" ...
0 votes
1 answer
2k views

Converting csv file (generated by db query) to html and color code the table based on Column Value

(Using Shell Script) Need to generate html report from a CSV file which is an output of a DB query and then color code it based on column values. For example, from the given CSV ile, if any cell under ...
0 votes
1 answer
2k views

Installation of latest version R for linux

First I typed sudo gedit /etc/apt/sources.list after that I got one sources list then I typed deb http://cran.rstudio.com/bin/linux/debian wheezy-cran3/ then I get the error like this No command '...
33 votes
3 answers
15k views

Spaces in variable assignments in shell scripts

What is the difference between below variables assignments? var=23 var =23 var= 23 var = 23 Is there any difference in space around the assignment operator?
21 votes
3 answers
53k views

" sudo: source: command not found"

$ source /etc/environment $ sudo source /etc/environment [sudo] password for t: sudo: source: command not found It seems that a different shell than bash is run to execute source /etc/environment ...
-7 votes
0 answers
33 views

I have recharged on 10 th May for 84 days of validaty , what will be my next recharge date & month ....#Shell_Scripting [closed]

After running the script , it should print the day & month of next recharge date.
59 votes
3 answers
316k views

unexpected EOF while looking for matching `"' - bash script

I just wrote a bash script and always getting this EOF-Error. So here is my script (only works on OS X): #!/bin/bash #DEFINITIONS BEGIN en_sq() { echo -e "Enabling smart quotes..." defaults ...
111 votes
9 answers
171k views

Solving "mv: Argument list too long"?

I have a folder with more than a million files that needs sorting, but I can't really do anything because mv outputs this message all the time -bash: /bin/mv: Argument list too long I'm using this ...
1 vote
1 answer
33 views

Fish EDITOR environment variable does not seem to work

I recently started using the Fish shell. echo $EDITOR returns vim But yet, when using programs that need to launch an editor and look for it in the EDITOR environment variable they don't seem to find ...
0 votes
0 answers
12 views

zsh command expansion applies esacping [duplicate]

I have a string S, for which I want to replace every b character with \\ (two forward slashes). So this is what I have: $ S="abc" $ A=$(echo $S | sed 's/b/\\\\/') In bash I get the expected ...
17 votes
3 answers
24k views

ssh command with quotes

I have an odd error that I have been unable to find anything on this. I wanted to change the user comment with the following command. $ sudo usermod -c "New Comment" user This will work while logged ...
0 votes
1 answer
30 views

Toggling off verbosity in the find command

I'm trying to toggle off the verbosity of the find command while writing the results to a text file and sending the process to the background. I'm using this command: find / -ctime 7 1> /home/user1/...
0 votes
1 answer
27 views

Bash variable inside another another

I'm trying to evaluate dateFrom variable inside dateCalc variable that evaluate PHP command. dateFrom="2013-01-05" dateCalc=$(php -r '$date = new DateTime($dateFrom);echo $date->add(...
-1 votes
0 answers
51 views

Find the optimal value [migrated]

Let us say I have a program called foo. It takes 1 argument (e.g. foo 42) and it spits out a single line containing a numerical value (e.g. 2034). I want to find the optimal value for the input ...
7 votes
3 answers
5k views

Why $0 is not a positional parameter?

I have read that positional parameters start at $1 (for example: $1, $2, $3 and so on are positional parameters). But $0 is not a positional parameter. But why $0 is not a positional parameter? I ...
5 votes
4 answers
23k views

How to use / send signals at the command-line, for any program (eg. dd)

I trying to understand the manpage of the dd program, which mentions: Sending a USR1 signal to a running 'dd' process makes it print I/O statistics to standard error and then resume copying. ...
1 vote
1 answer
21 views

Read content of file in ksh and split it by ','

My file.txt contains the following content:- ./raw_input/0009/img.raw,./raw_input/0009/calib.raw
1 vote
2 answers
589 views

Fix corrupt /bin/sh link

I used to access it via SSH but I wanted to connect to it with zsh instead of bash. I made a mistake with my Synology NAS: I deleted the /bin/sh symbolic link to /bin/bash to replace it with /bin/...
0 votes
1 answer
44 views

How to Store the Output of a for Loop to a Variable

I have the following shell code: for value in 10 5 27 33 14 25 do echo $value done But what if I want to manipulate the output later? I want to store the entire output in one variable. Is ...
1 vote
2 answers
34 views

Script to find all empty git repositories on a machine

We know an empty git repository only has the .git directory in it. I want to find all git repositories on a machine, which are empty. I thought about this process: Find all directories that are named ...

1
2 3 4 5
228