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, …).

learn more… | top users | synonyms (1)

0
votes
0answers
32 views

Significance of shell script with XML

I have recently joined anew project and experienced the structure where Shell scripts are usually directed to a target which is set in XML and that XML containing action in the tags which needs to be ...
1
vote
2answers
110 views

How to make sure that a child process of a supervisor job dies when I kill supervisor

My app is a jar file that requires some environment variables. I have all the environment variables in one file, which looks like this: export VAR=value export VAR2=value2 #....etc My supervisor ...
5
votes
3answers
496 views

Exclamation mark variable `$!`

I have been studying for my Unix exam and I often saw exclamation mark variable - $! If I write echo $! on my Mac shell tells me something like "You have mail in…" Is purpose of this to store whether ...
1
vote
3answers
57 views

Variable assignment syntax error in shell [closed]

VALUE=${VAR| |o} I found this variable assignment in shell script. I can't understand why || sign is used here. EDIT Code given in a comment: #!/bin/bash source /opt/cpf/bin/cpf_logging_helper.sh ...
1
vote
1answer
74 views

Bash Function Parameters - Spaces in Filename [duplicate]

I know there are rules for quoting parameters, but no matter what I try, I can't seem to figure out how to make this work. I have a function that takes a single filename as a parameter, then uses ...
2
votes
1answer
51 views

Accessing random array element in ZSH

I have ZSH as my primary shell, and I'm trying to randomise access to an array. I keep seeing feh called, but I don't have that command. I have _feh, but I don't know if it's the same thing. What is ...
53
votes
10answers
4k views

Use of touch and vi?

Is there a benefit of creating a file with touch prior to edit.. like: touch foo vi foo versus getting it to editor straight-away? Like: vi foo I see quite a few tutorials using the former (...
1
vote
1answer
27 views

when the cron job start after installing new crontab?

I need to a crontab execute each 12 hours, so I have the following: 0 */12 * * * . /X.sh then Linux is installing new crontab. after that, I am waiting for 2 hours and still the cron job didn't ...
4
votes
3answers
368 views

Executing of all shell scripts in a directory starting with the letter 'a'

I have many shell scripts in a directory starting with letter 'a'. How could I execute all of those shell scripts at a shot? Can we develop any other small script to run this?
0
votes
2answers
56 views

To include double quotes within a string

My command is X=`ssh ${OS_USER}@${OS_HOST} ". ~/.kshrc ; ulimit -c unlimited ; cd ${OS_PATH}/NEW_BL1_RC_RATE/bin/conf; echo "export RC_DB_INSTANCE=$7" >> RC_CONV_SET_VARS"` $7 should ...
0
votes
1answer
22 views

Redircting stdout to file, but duplicating stderr to both file and terminal [duplicate]

Redirecting stderr to file and duplicating stdout to both file and terminal is easy: $ prog 2>error.log | tee output.log tee will duplicate stdout, printing it to both terminal and output.log. ...
7
votes
4answers
132 views

How do I determine if a program is running when I start a shell and start that program if it is not already running?

When I start a shell, in my case bash and/or zsh, what lines do I need to add to .zshrc and/or .bashrc to check to see if a program is already running, and if the program is not already running, start ...
13
votes
3answers
881 views

How to remove \n between the outputs of two echo commands?

I have a text file containing one file name in each line: 111_c4l5r120.png 123_c4l4r60.png 135_c4l4r180.png 147_c4l3r60.png 15_c4l1r120.png ... I want to convert it in this shape: 111_c4l5r120.png ...
2
votes
2answers
67 views

how can I find files based on different names and delete all them in one single line [duplicate]

Finding files based on different names I know how to do. The problem is that I don't know how delete all of them at once. I am using OMVS in z/OS390. To find files searching by different extensions I ...
-1
votes
2answers
165 views

How to sum many numbers inside 2D array using awk

I need to sum numbers located in a file like this one: column1 column2 column3 row1 a(1,1) a(1,2) a(1,3) row2 a(2,1) a(2,2) a(2,3) row3 a(3,1) a(3,2) a(3,3) row4 a(4,1) ...
0
votes
2answers
58 views

Switch case not working in Shell

I am new to shell and am intending to use gdialog to take user input and feed it to switch case in shell. Below is my code: #!/bin/sh which gdialog 2> /dev/null && DIALOG=gdialog || ...
3
votes
1answer
63 views

How variables inside braces are evaluated

I'm new to shell scripting and I came across these expressions ${var:-val} and ${var-val} ${var:+val} and ${var+val} ${var:=val} and ${var=val} so how are they evaluated and what are the ...
1
vote
0answers
32 views

find-like tool to search (recursively) in MailDir folders by size, sender, recipient, attachment name regex, etc

I am not looking for a tool like locate, that works by creating an index in the MailDir, or generating other runtime files there; I am searching for real-time, direct search on live MailDirs. The ...
0
votes
1answer
41 views

Shell prompt displays .f>

I am running SSH through this command: ssh <machine-name> But instead of seeing the machine name in the prompt, I see .f>. Normally the prompt looks something like machinename> Any ...
10
votes
4answers
432 views

Run command after a certain length of time has elapsed?

If I'm executing a long process, is there any way I can execute some time-based commands? For example, I'm running a really long process which runs for roughly 10 minutes. After 5 minutes, I would ...
3
votes
1answer
21 views

Start new process group in .xinitrc

I have a statusbar (lemonbar) to which I pipe the output of a couple of scripts (time, battery, volume, etc.). These scripts, and the statusbar itself, are all started in a single bash script ...
2
votes
1answer
42 views

Get DISPLAY value by username

I run following commands to get DISPLAY value for a logged in user. $ loginctl list-sessions SESSION UID USER SEAT c2 1000 asif seat0 ...
3
votes
1answer
47 views

Shell syntax for redirecting arguments?

If I want to redirect not the stdio but as arguments the output of a program , should I use xargs? For example, I do ls and I want the filenames to be arguments to the next command rather than an ...
1
vote
1answer
43 views

Move files several directories up for several directories with similar layout

I have a directory with the following layout (the layout in Directory 1 is repeated in every other Directory <num>): Parent directory Directory 1 some directory another ...
1
vote
3answers
50 views

how to spawn a separate process in the background while running a foreground process

e.g., I want run a python -m HTTPSimpleServer in the background while running a watch in the background python -m HTTPSimpleServer; watch -n (my awesome test command) how can I run both in ...
2
votes
1answer
61 views

on-line tally of unique lines

uniq -c is very useful for counting the number of times the same line appears consecutively $ seq 1 1000 | awk '{ if ($1 > 100 && $1 <= 200) { print "hi" } else {print "bye"} }' | uniq -...
2
votes
4answers
53 views

Access a file located with find

In many cases after I find a file using the find command I then want to open the file or cat it or maybe print it. How can I operate on the result from find? For example, : find . -name "myfile.txt" ...
2
votes
2answers
113 views

what is the difference between “./command” and “bash command”

I have simple bash script file, it contains only one line: rvm gemset use --create 2.0.0@PRJ_NAME If I run this script with: ./scriptname.sh I get a well-known error message from RVM RVM is not ...
0
votes
1answer
50 views

How to merge or join more than 2 files? [duplicate]

I have four files; file1: gene_id FPKM TRINITY_DN56960_c4_g1 36.91 TRINITY_DN42427_c0_g1 12.83 TRINITY_DN48728_c0_g1 6.22 TRINITY_DN50706_c0_g2 6604.75 TRINITY_DN51449_c1_g1 8.19 ...
1
vote
2answers
57 views

Use variables in here-string

To feed input to an interactive script, I've been using a here-string: script <<< $'1 2\n3 4\n5 6\nq' This effectively enters 1 2 3 4 5 6 q into the script. But how can I replace one of ...
1
vote
2answers
22 views

Get owner / user of a cronjob

In Linux (Mint / Ubuntu), I can create cronjobs for each user individually. Is there any way, I can find out the name of the user against whome the cronjob is running. I want to get the username of ...
1
vote
2answers
48 views

A quicker way to change owner/group recursively? [duplicate]

Currently, when I want to change owner/group recursively, I do this: find . -type f -exec chown <owner>.<group> {} \; find . -type d -exec chown <owner>.<group> {} \; But ...
0
votes
2answers
42 views

Shell Script to insert lines in between file

Suppose there is one file1.txt where content is written Ramesh Suresh Raman From the below shell script ,I am reading the content name from file1 .txt and preparing the Name=$line in echo statement....
3
votes
4answers
146 views

Where should I save color codes for the PS1 command line / terminal? [closed]

This question is about best practices. I know logging in over secure shell or switching users su, and su -l have different effects. Also, in the event you make a typo in the configuration, you still ...
0
votes
0answers
78 views

Send command to open process in Shell file

In bash how can I issue a command to a running process I just started? For example; # Start Bluez gatttool then Connect to bluetooth device gatttool -b $MAC -I connect # send 'connect' to the ...
3
votes
1answer
33 views

.ksh session hangs after being inactive

While remotely connecting to a Linux machine using ssh, my .ksh session hangs after being inactive for sometime. If I try to type or ctrl-z, the prompt does not respond. Is there a way to restore my ...
4
votes
4answers
55 views

Does \ work for escaping functions?

I have a function defined in my .bashrc that I would like to bypass: function func() { // func } export -f func When I run env -i func I can access the func command without the function in the ...
1
vote
1answer
59 views

Shell Font Over SSH

I have a Linux machine (CentOS 7) in which I frequently SSH into from multiple devices. I have installed ZSH and Oh-my-zsh on the remote machine. I would like to install the following theme: https://...
1
vote
2answers
67 views

Help me please to find my misunderstanding about this little piece of shell script

Actually, I have a folder which contains several sub folders with lots of images in each. I am trying to gather all the names of the files in each sub folder in a text file (filesNames.txt) in that ...
0
votes
1answer
56 views

Validate user response in shell script

My shell script is working fine and the files are copying to the remote directory. However I need to check if my INPUT_STRING is starting with S and also check if the files are present in the ...
1
vote
3answers
70 views

Where are shell variables stored?

For example, if I make a parameter expansion: $ b=1 $ echo $b 1 Where is b stored internally? I checked and it is not an environment variable because it is not listed by printenv. I'm writing my ...
48
votes
5answers
3k views

Why is the wild card character * so different between commands zip and rm?

I put together a script to do some file operations for me. I am using the wild card operator * to apply functions to all files of a type, but there is one thing I don't get. I can unzip all files in a ...
1
vote
1answer
25 views

When a shell executes an external command/program - does that program have file descriptors?

There are alot of documents and discussion around the file descriptors of shells and how those file descriptors can be manipulated for redirection etc. My question is, when a shell command is an ...
4
votes
1answer
73 views

Exploit in bash script parameter possible?

I want to pass an e-mail address from a web form to a bash script. I'm using the following regex: /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}/ Is this sufficient? Or could one embed an exploit?...
2
votes
2answers
44 views

efficient wait until NAS boots to mount it

Problem: Server boots 3 minutes, Raspberry Pi boots 30 seconds. After a power outage, RPi boots faster and does not mount the NAS disk. This particular RPi needs disk to be able to record to it. ...
2
votes
4answers
60 views

Create text corresponding to multiple variable assignments from a single variable

I have a variable that has a value like this line=dog,/path1,/path2 What I want is to create a variable from the value; i.e dog should be the variable and want to get the below output: dog=/path1,/...
2
votes
1answer
33 views

Find differences of ownerships between two home folders?

I have two home folders: /home/masi and /home/masi_backup and I would like to find the differences between files of the two directories. Pseudocode vimdiff <`ls -la /home/masi` <`ls -la /home/...
1
vote
1answer
81 views

Get the canonical path for a command

I'm writing a script that needs canonical path of certain commands. Since there could be symbolic links pointing to the actual commands, I use readlink -f to get the canonical path. But I'm not ...
0
votes
1answer
31 views

how to echo/print block by block

I just started using tmux and butterfly and I need to scroll one panel. I tried Ctrl + b + ↑ but it scrolled the whole terminal instead of one panel. Is there any command line to display my ...
1
vote
1answer
44 views

xkill Used On Desktop

Mouse accidentally clicked on Desktop while active with an xkill terminal command. Which makes it completely without use. Have used nemo command which resets everything as long as terminal remains ...