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

Check Windows Defender Date Last Updated and update signatures if 90 days out of date in PowerShell and Bash

I need to Check Windows Defender Date Last Updated and update signatures if 90 days out of date in PowerShell What is the proper way to do this check in both PowerShell and Bash? Here is what I have ...
user avatar
-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: /...
user avatar
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 ...
user avatar
  • 11
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). ...
user avatar
  • 11
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: ...
user avatar
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 ...
user avatar
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|--...
user avatar
  • 135
4 votes
1 answer
183 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. ...
user avatar
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 ...
user avatar
  • 347
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 ...
user avatar
-1 votes
0 answers
21 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 ...
user avatar
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?
user avatar
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 /...
user avatar
  • 101
-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.
user avatar
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 ...
user avatar
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/...
user avatar
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 ...
user avatar
  • 133
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(...
user avatar
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 ...
user avatar
-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 ...
user avatar
  • 29.9k
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
user avatar
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 ...
user avatar
  • 135
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: ...
user avatar
  • 19
4 votes
1 answer
46 views

zsh: pass variable by reference, and modify its value (like bash's local -n namerefs)?

Is it possible to pass a variable to a zsh function, and modify its value without using eval? I came across a bash way to do that: local -n: https://stackoverflow.com/a/50281697
user avatar
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 ...
user avatar
0 votes
0 answers
20 views

Can I use inetd or xinetd as a web server?

I just want to know if it is possible to use xinetd as a web server to server simple piped commands. For example, I want the output of ps -ef|grep root|wc -l to be served over HTTP using xinetd (...
user avatar
  • 1,384
0 votes
0 answers
19 views

*nix shell: How to disable pipe buffering for ALL pipes in a command?

I want every pipe to be unbuffered, so I don't have to type stdbuf -oL for every piped command. When concocting commands with multiple pipes, it would be nice if there was a environment variable or ...
user avatar
1 vote
2 answers
36 views

How to move file contents deeper without copying

I have files in /home/jjblack/foo/. I want to move all the contents of this directory into /home/jjblack/foo/bar/. I am unable to copy the contents elsewhere as there is not enough disk space. I am ...
user avatar
  • 81
3 votes
1 answer
745 views

Can you rescue a shell from an accidental "yes" command?

Scenario: I'm running a bunch of commands, some of which prompt for "yes/no" answers. I accidentally type yes as a command instead of as a response to a prompt. OOPS. Now my shell looks ...
user avatar
0 votes
2 answers
32 views

Get value from a key value pair separated with pipe

I have a string as below Delete :xna.del|mode:Full|Execution: loaded I need my output to be stored in 3 parameters. for an example a=xna.del b=Full c=loaded
user avatar
-1 votes
1 answer
49 views

How to extract the characters after a forward slash using awk

How can I extract the substring after a / and compare the extracted value against another file ? cat file /abc|98357| abc/aabb|023947| xyz/0102|293847| pqr/pqrst|29384| 9864/truse|253123| expected ...
user avatar
0 votes
0 answers
14 views

How to disable and re-enable bracketed paste mode in xonsh?

How to disable and re-enable xonsh bracketed paste mode? It breaks pasting in interactive terminal tools that are started with keyboard shortcut. In fish I can run functions ...
user avatar
  • 577
0 votes
1 answer
31 views

(sed or an alternative in sh) if a line does not contain a dot (.). Then add XX at the end

Background information: Data exchange via csv between 2 programs. I have the following csv from program 1: > timestamp; name ; value > 1655709562;Var 1 Float;65.0 > 1655709562;Var 2 Float;...
user avatar
  • 3
0 votes
2 answers
23 views

Edit PATH variable in a shell script to remove specific enteries

I want to remove from the path environment variable all of the enteries that contain a certain word, how can I do that?
user avatar
0 votes
0 answers
11 views

How to wrap a process with an activity indicator?

I have a process which I'm running in a terminal session. The process prints nothing (or perhaps it prints a lot of junk which I redirect somewhere), and takes quite a while, e.g. a couple of minutes. ...
user avatar
  • 7,391
-1 votes
1 answer
64 views

How to source a script code (set a variable) from another shell?

I tried to use FreeBSD. The FreeBSD root user uses csh by default. user@freebsd-13:~ $ echo $SHELL /bin/csh I know that setting a variable via $() does not work in csh. root@freebsd-13:~ # export ...
user avatar
  • 271
0 votes
2 answers
37 views

why i need to run pipe(2) so i can share data between processes?

This is a follow-up question, UNIX-focused i m trying to implement my own shell and i got stuck in the pipe feature after some research i found out that i need to run pipe(2) to share data between ...
user avatar
0 votes
1 answer
27 views

Looping through a variable with newlines without a sub shell

I am trying to loop over a variable which contains newlines in a POSIX compatible way. The following works: echo "$REQUIRE_PURPOSE" | while IFS= read -r line ; do echo "$line" ...
user avatar
  • 9,356
1 vote
1 answer
27 views

How to send heredoc command to background?

I want to send a heredoc command like this one cat <<EOF line 1 line 2 EOF to background. (The actual command is openssl with many lines of input which takes some time to complete). The command ...
user avatar
2 votes
1 answer
554 views

Why is using "|" or "&" provide different sizes of the result file?

Here is my explanation: strings *.bin > bin.txt | sort -n bin.txt > logs1.txt that gives me logs1.txt, but it has 621 KB. strings *.bin > bin.txt & sort -n bin.txt > logs1.txt that ...
user avatar
  • 29
2 votes
2 answers
67 views

How Can I Find Five Numbers Between Two Numbers

Suppose I have these two numbers: 800000 and 3200000. I want to find five numbers with an even difference in between these two numbers. Therefore, I want the output to be: 800000 1200000 1600000 ...
user avatar
  • 135
0 votes
0 answers
24 views

What's the recommended way to install files and modify rc files?

To help developers set up some of their environment, I have some small files that need to be installed to various locations in a user's home directory, plus modifications that need to be made to some ...
user avatar
  • 308
0 votes
1 answer
29 views

pass text from file as arguments after running variables

I've got this example: [nir]$ cat a.cfg --arg1 $(./get.sh variable) [nir]$ cat get.sh echo "${1}-info" [nir]$ cat a.sh arg=$(cat a.cfg) echo "$arg" [nir]$ ./a.sh --arg1 $(./get....
user avatar
  • 1,165
-2 votes
1 answer
65 views

Using 2 For loop print the output of 2 answers from two different files

I have 2 files with some content/lines. Example : cat a.txt 1 2 3 4 cat b.txt a b c d Need to get below output using for loop 1 a 2 b 3 c 4 d I have tried the below script but ...
user avatar
  • 1,820
1 vote
1 answer
51 views

Get output of a command that uses curses

If I try to get the output (stdout) of a python program into a variable I do this: set zpath (python something.py "$argv") But if the program spawns a curses interface, it won't show. The ...
user avatar
  • 189
0 votes
0 answers
23 views

Validating only four digits using SED

In the SED command, I only want the SED to work if there are SOMETHING_4DigitsHereOnly_SOMETHING2. For example, if the file name is ITALY_2022_BEST1FRIENDS2_ROME.txt . I only want 2022_BEST1FRIENDS2 ...
user avatar
0 votes
0 answers
28 views

Strange behavior when running top through ssh [duplicate]

It's strange that neither ssh user@192.168.1.59 bash -c "top" nor ssh user@192.168.1.59 "top" works as expected, whereas both ssh user@192.168.1.59 "ls" and ssh user@...
user avatar
  • 228
0 votes
1 answer
27 views

mouse click after ssh connection broken

I have logged into a remote server by ssh in the terminal. The connection was terminated due to the server going down or a network problem. Then something annoying appears. Once I click the mouse on ...
user avatar
  • 2,636
1 vote
2 answers
55 views

sh does not take $PATH into account

This works sh /opt/gap-4.11.1/bin/gap.sh This does not work sh gap.sh and returns error message sh: 0: Can't open gap.sh But the required directory is in $PATH, as confirmed with echo $PATH /usr/...
user avatar
  • 21
0 votes
1 answer
69 views

how to get the value of parameters in quotes in bash script?

I am using this command: curl -I "http://localhost:8080/jobname/buildWithParameters?ENVIRONMENT=UPPER_DEV&IP=$HOSTNAME" I am giving some part of this: echo '"$HOSTNAME"' I ...
user avatar
  • 1

1
2 3 4 5
228