Stack Exchange Network

Stack Exchange network consists of 174 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....

0
votes
0answers
9 views

find: prune n different directories and m different files at any level but include few files in some pruned directories

I want to recursively find all directories and files inside a path but want to exclude some other directories and files that match given patterns. I then want to execute further commands on the search ...
-2
votes
1answer
23 views

How to append(both prefix and suffix) a string

I have a file called b.txt with following content libiomp5.so libmkl_avx.so libmkl_core.so libmkl_def.so libmkl_gf_ilp64.so libmkl_gf_lp64.so libmkl_gnu_thread.so I want to prefix following string ...
0
votes
1answer
34 views

Nested double quotes for wrapping variables

There is one line in my bash script file like this: echo "$string" | sed -e "s|\($str\)|$(wrap \\1 $1 $2)|" Now, I want to wrap the $1 and $2 with double quotes for preventing errors while $1 equals ...
-2
votes
2answers
25 views

Replace a variable with stdin?

I want to loop over some values and I know I can simply use a for loop but is there any other way that I can replace a variable value in a command at the end of the command? Somewhat like echo 11"$...
0
votes
1answer
16 views

What do I need to do to get qrandom to pipe data correctly into a running script without it throwing errors?

Recently, I have failed to input data from qrandom with a script. The pipe script is down below. while true do echo 1 echo $((qrandom --int --max 69 --min 1)) echo 2 echo $((qrandom --...
-1
votes
2answers
38 views

BASH Creating unique username [on hold]

I want to create a unique username based on the following bash script. The variable "user" should change based on the following criteria below. How would you achieve this? tput cup 18 18 echo "...
0
votes
0answers
27 views

Comparing record count within a same file [on hold]

I am new to shell scripting . I want count the number of linea in my file and compare it with the record count available in the trailer record.. How to do that? I tried this (wc - l filename ) to ...
-3
votes
1answer
19 views

Comparing two fields from two files and printing the common items from the files with the count from each file

I have two files in a below-mentioned way File1 Emp1 Dec10 12Am Emp2 Dec10 2Am Emp3 Dec10 4Am Emp2 Dec10 6Am Emp1 Dec10 8Am File2 Emp1 Dec11 12Pm Emp2 Dec11 2Am Emp1 Dec11 3Am Emp3 Dec11 ...
-2
votes
4answers
27 views

Attempting to get this program to only print Usernames that are between 5 and 10 characters long [on hold]

I have written a bash program that scans through /etc/passwd and prints out all of the usernames that are in the directory however i need the program to only print out usernames that are between 5 and ...
2
votes
2answers
31 views

Need to iterate through subdirectories, concatenating files, with an iterative number

I'm trying to concatenate files from three different subdirectories into one file. The names of the files in each subdirectory are exactly the same. I'd like to use a loop to iterate through the ...
2
votes
1answer
46 views

How to run multiple processes and exit if any of them exits or fails

I am running multiple processes and want to exit with the appropriate exit code (this means error on failure, success otherwise) if any of them fails or exists. Additionally if any child process ...
0
votes
5answers
40 views

Transpose a single column of a CSV file

I have a CSV file with two columns namely column 1: file name column 2: access status The following are some sample recotds FileA, CREATE FileA, MODIFY FileA, DELETE FileB, CREATE FileB, ...
0
votes
1answer
29 views

Get every IP except for the loopback device

I need to get every IP of an host PC over the shell, except for the loopback or localhost devices. If I use ip addr show I have the loopback devices with it. Also I cannot ask for the ip addr show [...
-5
votes
0answers
37 views

For loop is not working [on hold]

cd $SSPATH FCSV=`ls *.csv` for j in $FCSV do GETR=`echo $j | head -c4` echo "File Name: $j " echo "First four characters: $GETR " temp=${GETR}_str.dat echo "Value of temp: $temp " ...
1
vote
0answers
58 views

Some commands not persisting between terminal sessions [on hold]

I am running Ubuntu with a zsh shell, and for some, primarily non apt-get installed cli utilities, I get a command not found error in the cli, when trying to open that application in a new terminal ...
0
votes
1answer
24 views

variable containing output of docker exec command malaligned

I am trying to run bash inside docker container using docker exec bash -c and store its output on the host(not the container) by echo'ing something which will be used in conditional statement. I could ...
0
votes
2answers
44 views

An echo operation includes some piece of text it should not include

On a WSL Ubuntu 16.04 (Xenial) with composer I executed: echo 2 * 3 > 5 is a valid inequality It resulted in a file by the name of 5, with the content: 2 composer-setup.php 3 is a valid ...
2
votes
6answers
357 views

How to get a bash script argument given its position from the end? [duplicate]

I've got a shell script and I want to use the last argument: #!/bin/bash echo My last param is #somehow put it here Here is what I've tried: echo $$# echo ${$#} echo ${(($#))} Unfortunately it did ...
2
votes
4answers
69 views

Backreferencing in bash

I'm trying to devise an "elegant" solution to doing the following: unzip applications/<abc>.zip -d applications/<abc>/ unzip applications/<def>.zip -d applications/<def>/ ...
-1
votes
2answers
50 views

How to print the first line which include special word [on hold]

Print the first 123 below XXX AAA BCB DDD 123 123 XXX CCC 123 123 MSM 123
1
vote
5answers
100 views
+50

Alternative to wait -n (because server has old version of bash)

I would like to solve the following issue about submitting a job that has been parallelised to a specific node. Let me start with explaining the structure of my problem I have two very simple Matlab ...
0
votes
3answers
46 views

Backing up dotfiles with a shell script

A simple shell script is needed to copy dotfiles, adding a .backup extension, i.e., .dotfile1.backup. The script below will not work because it adds extensions to pre-existing backups forever and ever,...
-2
votes
1answer
36 views

bash script that will go through all files in a directory listed as as the first argument

I need to write a bash script that will go through all the files in the directory listed as the first argument. It will print out the name and file size of any file that is less than 100 bytes long ...
0
votes
0answers
24 views

Why did install command overwrite (destroy) my directory? [closed]

I was viewing the output from Makefile.pdlibbuilder, and it looked like this: .... install -m 755 -d -v "/usr/lib/pd/extra/MyPlugin~" install -p -m 644 'MyPlugin~-help.pd' "/usr/lib/pd/extra/MyPlugin~...
-3
votes
0answers
17 views

bash script to check an email box by sender and subject and then set a monitoring status alarm [closed]

I would like to write a bash/shell (on gnu linux) script that checks a certain email box by: sender, subject, and then if the sender and subject is "x" and "y" it should return a monitoring tool code (...
0
votes
1answer
18 views

Send value to a “read” in a script

Is it possible to send a response to an "interactive menu" in a shell script but directly when calling it ? For example, the script test.sh : #!/bin/bash sleep 2 #Or something else echo "menu, ...
1
vote
1answer
11 views

How to extract data from csv file with modification to data

For eg i have a file called test.csv containing emp1,dep1 emp2,dep2 emp3,dep1 emp4,dep3 emp5,dep2 expected output is emp1 works in dep1 emp2 works in dep2 . . emp5 works in dep2
0
votes
3answers
32 views

Exit pipeline early on command failure

I looked at Exiting a pipeline if a former command fails but I'm looking for a more general solution to this problem: chlist -q -v -m -r $sourcelist | \ grep '^USER:' | \ chlist -q -v -f - $superlist ...
-1
votes
1answer
31 views

Bash: weird parse output? [duplicate]

I'm working on a simple script that accepts multiple command line arguemnts in an order: #!/bin/bash function arg_parser () { while [[ $# != 0 ]] ; do case "$1" in --one) varone="$2" ...
-1
votes
0answers
24 views

Remove Duplicate Records in A csv file [closed]

I have a CSV file with pipe separated 40 column , In this file there are so many duplicate records. I want to remove all duplicate records on the basis of 20th column records
1
vote
1answer
32 views

Bit banging with dd?

I need to change one byte at a well-known position of a binary file to a specific value, and am looking for a way to achieve that using command line tools. Constraints: I need to change one single ...
2
votes
1answer
75 views

How to retrieve counts of IP addresses from log file?

I am checking a log file to retrieve ip adresses plus how many times a log failed. This is what my log file looks like: Feb 2 15:20:02 tank sshd[14870]: Failed password for root from 143.100.67.173 ...
-2
votes
0answers
38 views

Shell script that serves as a checklist [closed]

I have to write a shell or bash script called "valid" that validates a handed project. For example, the name of the project to be validated is: project.md This file is supposed to be the same ...
0
votes
0answers
11 views

How to pass automatic inputs to jar engine while running a wrapper shell script

I am working on wrapper script which will execute 10 script in a sequence in a given specific time by scheduling crontab for the wrapper script .Here i have a challenge we have a third party java ...
0
votes
1answer
29 views

What is a good command for moving a directory containing relative symbolic links to files outside the directory?

I like to use relative symlinks when possible because they stay valid even when my filesystem is mounted in a non-root location, for example if I am accessing it remotely. However, if I move a ...
0
votes
3answers
41 views

How to replace a number by its corresponding string (low/high) in bash?

I have a file: property(Address1, 4.5) property(Address2, 2.2) property(Address3, 9.0) property(Address4, 3.4) --- I want to replace the floating points based on some conditions (For example: if the ...
0
votes
1answer
42 views

What is /dev/vcs* on Linux?

man vcs(4) is Greek to me. I'm running Lubuntu 18.04 with the LXDE graphical user interface. When searching for an answer to my other question, Where is terminal output stored?, I found that /dev/...
2
votes
1answer
72 views

Why I can't pass a parameter from cron to shell script [closed]

With this cron script I am trying to get Rsync to work */1 * * * * /root/backup.sh `date +today/\%M` And a shell script as the one below #!/bin/bash -x PATH=/bin:/usr/bin:/sbin:/usr/sbin REMOTE=...
3
votes
2answers
34 views

Why isn't $foo=* results in an error?

I've learned that the shell expands certain kinds of characters. That's why when writing: $ echo * I get a list of directories and files, let's say I get: Applications Desktop Documents now, Let's ...
1
vote
0answers
8 views

Why is it that I cannot open file in terminal when in root? [migrated]

I have a file in MacOS that I want to change that is protected by permission restrictions. I cannot access it with my normal account. I use terminal to log in to root, and try to open the file as such:...
12
votes
1answer
328 views

Find description in man pages for environment variables shown with env command

In man pages, where can I find a detailed description of the environment variables that are listed when env command is run? I have tried man env but it only provides me one example for TZ environment ...
2
votes
4answers
256 views

shell scripting for jenkins

My Jenkins environment variable $SVN_URL is http://project/svn/neslrepo/trunk/java_project. I want to extract java_project and store in a variable through my shell script. I tried: job_name=(echo $...
-1
votes
1answer
15 views

How to backup a file by date located in a remote server

I am trying to backup a ".jar" file which is located in a remote server. I wrote a shell script to do this but when I execute the script ssh is only working. Only one "jar" file is located in the ...
4
votes
1answer
80 views

Testing if a file descriptor is valid (for input)

In the question "Testing if a file descriptor is valid", a test is sought for testing whether a file descriptor is opened or not. The answers all focus on testing whether the file descriptor is ...
0
votes
1answer
49 views

Move all files into subdirectories named after part of file name [duplicate]

I have a directory that contains quite a lot of files with names made up of artirst's name and album e.g.: Now the task is to go through each of the files, create a directory named after artist's ...
0
votes
1answer
43 views

? at the end of files in while listing file using 'ls'

While listing files using 'ls' command I get the following. -rw-rw-r-- 1 vineesh vineesh 2026 Nov 28 15:48 cdfg_ulit_89.txt? -rw-rw-r-- 1 vineesh vineesh 1215 Nov 28 15:48 cdfg_ulit_8.txt? -rw-rw-...
1
vote
3answers
92 views

Grep string only in uncommented line

How can I grep the string which is only in uncommented line? I don't want the result to be included for string in commented line. For example: In file.tx My name is Jane #My name is Sara I want to ...
0
votes
1answer
53 views

Store a path in a variable and use it with cd

I have a path as, Sample_Backend_Parameterized_Deployment I want to set this path into a variable and call it later. How can I do it? I tried this and not working CDPATH="...
0
votes
0answers
14 views

Process “IP-m” (e.g. 192.178.12.1-m) causing temporary freeze

I am currently working on linux cluster and since a while, I am experiencing some issues which I cannot resolve (and also the sys admin is puzzled). Every once in a while (but quite regularly), the ...
0
votes
0answers
22 views

Replace properties in a file from linux shell commands

I used below command to update the application.properties file. But it is not working. REPLACEUN=test REPLACEPW=test@123 sed -i "s/\(spring\.datasource\.username=\).*\$/\1${REPLACEUN}/" test- ...