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

Discover what file stdout is being written to

Answer is probably out there somewhere - say we have a shell redirection: node foo.js > /tmp/foo.log is there a way from the node.js process to determine which file stdout is attached to? I ...
0
votes
0answers
20 views

How to list all internal commands of a shell

Is there any way to list all the internal commands of a shell. I am using bash shell. if I type echo then bash has internal echo command so internal echo command will be executed( Internal command ...
-2
votes
0answers
28 views

Find difference in two files

I have two files like below: file1.txt a 2019 15 b 2019 20 file2.txt a 2020 10 b 2019 15 Desired output contents of file1.txt & diff bw third columns( from file1 & file2) With respect to ...
0
votes
1answer
27 views

word count redirect

I can't seem to answer this question: Use the command wc to count the number of words in the file /course/linuxgym/gutenberg/0ws0310.txt. Store the exact output of the wc command when used with the ...
0
votes
0answers
30 views

How to remove duplicates in excel both rows and columns using shell or awk script across multiple files

How to remove duplicates in excel both rows and columns using shell or awk script across multiple files. If the second file contains a row which already exists in previous file, then it should be ...
-4
votes
1answer
41 views

Writing a bash shell for loop question [closed]

trying to write a Bash shell for loop that will iterate through each line of the confidential.hex file and add each line of the hex string to the name of target domain name server, ns.example.com and ...
-1
votes
4answers
33 views

Mv files with number formatted in 2 digits

I would like to mass rename files from: "02 Disc 01 My Song.mp3" to "Disc 01 My Song 02.mp3" How can I do this in bash? Please note that all numbers are formatted in two digits (1-9 is ...
0
votes
1answer
20 views

How to Search XML Block and Delete the same

This is my XML. <configGroup> <type>SERVER_CONFIG</type> <configProperty id="Server48"> <configProperty> <name>Server Name</name> <...
0
votes
0answers
12 views

Is there a way to pipe to a visual editor and then continue the pipeline? [duplicate]

I know that some command-line programs can open visual editors like Sublime in a "wait mode" which opens the editor, lets you edit, and on-close it resumes the program with the file contents (like git ...
4
votes
4answers
637 views

Print multiple empty lines without repeating \n

echo is used to produce a new line in Linux. echo -e '\n' 2 lines echo -e '\n\n' 3 lines and so on. e.g. user@linux:~$ echo user@linux:~$ echo -e '\n' user@linux:~$ echo -e '\n\n' user@linux:~$ ...
0
votes
1answer
15 views

Get the last value appears in column Y for unique value appears in column X

I hope the title is not confusing.. I have a daily report file contains information about regular retailers, their transactions and their balance after each transaction. example: TransactionDate;...
8
votes
3answers
970 views

Where can I find a definitive answer for what `*/` means in Bash or Zsh?

I was trying to look into some reference from O'Reilly about Unix and Bash about the meaning of */ but couldn't find any. We can echo */ and see all the directories. It seems like it means all "...
-1
votes
1answer
40 views

I'm looking to pass 1 line of a .txt at a time into a shell script as a grep search argument

basically trying to make a shell script to run a grep on a certain directory for each line of a particular .txt, then output the results to a .txt that is named the same as the argument. for %...
0
votes
0answers
24 views

How to break out of read loop in pipeline consumer

I have this mini script: #!/usr/bin/env bash do_tests(){ # todo } go run . | ( while read line; do if [[ "$line" == "listening" ]]; then do_tests # run this once! break;...
0
votes
2answers
35 views

Bash scripting loop concatenate pipes / redirections based from names variable

I have a command that produces a number of output lines that I later grep searching for. Based on a past answer I know I can use a single long command and do all my filters concurrently: https://...
1
vote
0answers
16 views

Replacing File Content [duplicate]

I have a file named EX.txt with content inside of it: user='\''member'\'' I want to use sed to replace those '\'' to ' so it would be like this: user='member' But it didn't work when i use sed -...
1
vote
2answers
34 views

Identify directory other than some selected directory

I'm working on a shell script and having one issue. If I have a file with list of directory and files info like: home/svdev/src/lib home/dev/project/doc home/server/etc dev.dump/trunk/src dev.dump/...
1
vote
3answers
24 views

Shell script, get/extract mac address from console output of command after “MAC: ”

I'm trying to automatically pull out the mac address of a arduino device using a shell script, and need some help how to do this. This is the output returned by the command: Opening /dev/cu....
0
votes
2answers
34 views

using sed in a for in loop to remove words from file

I have a file 'book'(not txt) which contains text. I also have a list of words which I need to delete from said file. I have written this script but for some reason when I try to check and see if the ...
0
votes
1answer
50 views

Searching for numbers bigger than 1000 in bash

I'm a bash begginer and I want to solve the next problem: Find all the files in a directory received as command line argument that contain numbers greater than 1000. If the command line doesn't ...
0
votes
0answers
20 views

Bash script - Watch serial-port for specific string, then send back commands

I try to use a bash script to watch the serial-port for a specific string. If this string is shown, some commands should be send back to the connected device. It´s a router I am connected to. It is a ...
3
votes
3answers
61 views

I have multiple filenames with different versions . how to pick the highest numbered version from every filename

I have multiple filenames with different versions . how to pick the highest numbered version from every filename . ex: BMS-CEI2_BC-ADAP-19.04.1111-4_1.noarch.rpm BMS-CEI2_BC-ADAP-19.04.1112-4_1....
0
votes
1answer
21 views

How to replace multiple file lines with an edited grep output?

I grep recursively in a directory, now I got an output. Look through the lines, I change lines what I need to change, and remove lines what I don't need to change. like grep.txt ./path/a.c:12345: ...
0
votes
0answers
17 views

Where is the information of the hash table stored? In other words, where is its database?

The "command hashing system" should store the path of the shell commands somewhere, right ? Is it a database or what? I am wondering where that is. Also, Is it encrypted ? Do we have a way of ...
1
vote
1answer
41 views

Piping curl http://cheat.sh/python to less is showing strange ESC[38;5;246m [duplicate]

I am kinda new to Linux. My base issue: I need to show the output of curl cheat.sh/python like a man or less page, so that I can easily scroll up and down. What have I tried: curl cheat.sh/python | ...
1
vote
2answers
38 views

Running a command with root priviliges without SUDO and not as root user

How can you run a command (e.g. iftop or similar) that requires root privileges from a non-root user and without using SUDO in front? Alternatively, how can you give root privileges to a user ...
0
votes
1answer
30 views

Equivalent of `readlink` on SFTP

When I log into an SFTP server through the shell using sftp, I can navigate using the usual cd etc commands. One command I use frequently outside of SFTP is readlink -f $FILE to print the full path ...
0
votes
0answers
21 views

How to recursively encrypt all data in a folder recursively?

I can use: for f in .* ; do [ -f $f ] && openssl aes-256-cbc -in $f -out $f -k PASSWORD ; done to encrypt all hidden files in a folder and use: for f in * ; do [ -f $f ] && openssl ...
0
votes
1answer
36 views

Why zsh isn't recognizing apps with binaries on $PATH? [closed]

I have a mess with my binary files. I installed apps with pip and npm globally. I don't know why, when I launch the terminal (zsh,$SHELL=zsh) I can't use them, I have to run fish and come back to zsh ...
0
votes
1answer
44 views

Locally install a man page

I'm trying to make a script to locally install in a designated folder a personnal man page. I've tried changing the manpath, but this does not work.. My only objective is to let the user use : $ ...
0
votes
1answer
20 views

Shell scripting to print multiples of 5 including 1 and 100 [duplicate]

#!/bin/bash x=1 while [ "$x" -lt 20 ] do echo "$x" x=("$x" * 5); done Getting error as syntax error near unexpected token `done' and getting output as 11111111111....
1
vote
1answer
49 views

Is possible to execute command as root when switched from root to user using su?

Same as topic. I'm root. Then switch to user1 using su - user1 Then execute command as root without sudo or suid/chmod. Is it possible? One person probably did this but tells me it's a magic trick....
0
votes
0answers
18 views

How to add error handling for ansible shell module with pipes?

I have an Ansible shell module like below. - name: "Verifying file" shell: cat filename | grep something | tail -1 | awk '{print $4}' register: hname How to do error handling like if one pipe ...
0
votes
2answers
36 views

Count the sum of wc -l command output

i have a workspace tree like : /Directory /Dir1/file1, file2 /Dir2/file3, file4 /Dir3/file5, file6 ... I want to count the sum of the number of lines for each file in dir. I have this script,...
0
votes
0answers
22 views

DD command: Create an partition image without save filesystem

I have the initial situation: I have executed the commands: sudo dd if=/dev/sda1 of=~/part1.img sudo dd if=/dev/sda2 of=~/part2.img After this, i have prepared the new partitions for restoring the ...
0
votes
1answer
20 views

how to get error from running shell script in java?

i'am using java to run shell script it works great . now i want to get errors from this script for example i have a script and there is an error i want to get the line and a message of that error ...
0
votes
3answers
54 views

Run a command if stdin is empty

I'd like to do the reverse of xargs --no-run-if-empty, so that it ONLY runs if the stdin is empty. Example use: ip a | fgrep "inet " | grep -ve " tun" -e " lo" # pipe it into something and echo ...
1
vote
4answers
74 views

Reading from stderr in c

This is my c program read from stderr i write #include <uninstd.h> #include <stdio.h> int main(void) { char buff[3]; read(2, buff, sizeof(buff)); printf("%s", buff"); return 0; } My ...
0
votes
1answer
33 views

Exact string search in array

I have an array like: moduleList=(AB, ABCdef, ABCd) My array is numerically-indexed array not an associative array. I want to do an exact match for each element in array and to perform certain ...
0
votes
0answers
28 views

Bash inconsistent behavior between echo / assigning a variable with `set -e` and subshell

#!/usr/bin/env bash set -euxo pipefail echo $(echo "$THIS_VAR_DOES_NOT_EXIST" | cat) echo "WTF" Running this script produces: ./wtf.sh ++ cat ./wtf.sh: line 4: THIS_VAR_DOES_NOT_EXIST: unbound ...
0
votes
1answer
22 views

assign nmap output to several variables

I am using nmap to scan my network and want to show every device that is up. The following works great: ips=$(nmap -sn 192.168.1.68/24 -oG - | awk '/Up$/{print $2, $3}') What I now want to to is to ...
0
votes
2answers
83 views

find: ‘count=1’: No such file or directory

Previous code: total=`ls -Rp rootfs | wc -l` count=0 When I assign a simple addition to a variable: sudo find rootfs -exec cp -d -- "{}" "/media/$USER/{}" 2> /dev/null \; -exec sync \; -exec ...
9
votes
2answers
757 views

ShellCheck is carping that my expression is not in double quotes when it really is; why?

I'm writing a bash script with the AWS CLI and shellcheck is giving an error that I think is incorrect. I'd like to try to figure out why its carping. Here's the code, and error message: for server ...
-1
votes
1answer
18 views

In subshell how do you get its process id? [duplicate]

I know I can get process id of the main shell by $$, but how do you get PID of subshell created by e.g. ( ... ) from within the block?
2
votes
1answer
57 views

How to get PIDs of shells in pipeline? [duplicate]

For example, I run sleep 1 | sleep 2 | sleep 3 & How do I get process ids of each part? I could examine output of jobs -l but its format may wary among shells and I am looking for a simpler way.
1
vote
1answer
20 views

How to recursively copy files as hard links into directory preserving directory hierarchy?

I'm trying to hard link files in one directory hierarchy to another directory. Code looks like this: # Directories first, works fine, takes sub-second find src_dir/sub1 src_dir/sub2 -type d -exec ...
0
votes
0answers
27 views

Startx with multiple command without a file

I'm trying to run a graphic application from command line (i.e chromium) with some extra programs (i.e. cec-control, resolution settings etc). So far I'm able to do that running startx with the file ...
0
votes
3answers
74 views

one shell command to find every n-gram works in text

I have a text stream or a file that contains words separated by whitespace.  Like: I have a toy. you may not like it. Every whitespace-separated word may be composed by two or more small words, ...
-1
votes
1answer
31 views

Need to capture the file name from the directory path by looping the data file

I have the following data file. recID# Attachment# Attachment#2. ...... Attachment #15 101 c:/a/b/c/d/fil1.txt c:/a/b/c/d/e/aaa.txt ...... c:/a/b/c/d/e/fff.txt ...
0
votes
1answer
37 views

Shell script to scroll down the whole text in terminal without modifying it

I'm trying to use a /bin/sh script to scroll down a couple of lines of text in terminal. A solution using smcup, rmcup is not acceptable in this case. A couple of other options I tried all failed (...

1
2 3 4 5
192