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)

2
votes
1answer
136 views

specify shell for ssh session

I am logging to a remote server via ssh as user www-data. User www-data on the server has his default shell set to /bin/sh, and when I log in, I get dash as my shell. I can then type bash and get bash ...
1
vote
2answers
63 views

Wait until a process comes back from sleep

script.sh is run by run.sh N times in parallel. For N=1, the script.sh process is set to sleep 30-45 seconds before it actually starts. How can I order ALL script.sh instances for N>1 not to start ...
12
votes
1answer
256 views

Setting temporary bash aliases when entering a folder

Sometimes I like to have very customized bash aliases and maybe keybindings when I enter on a folder (can be a project where I'm used to type lots of commands from CLI). Lets suppose when I enter a ...
0
votes
1answer
40 views

Difference between set variable “value” and set variable value?

What is the difference between the following 2 examples in a shell script: set variable1 "value" set variable2 value
1
vote
2answers
67 views

Copy files that are created today without FIND command and SFTP to another server

I have a directory with 'n' number of files in it. I am trying to write a shell script which will list only the files created on the particular day the script is running, and will use sftp to move the ...
0
votes
1answer
37 views

find: missing argument to '-exec'

this is my first post, as I am completely new to the programming world. Basically I'm taking a UNIX class and I have an assignment asking me to check the size of regular files in my home directory for ...
5
votes
1answer
673 views

When files are being moved are they stored in a memory?

When I move a file using the mv command, is this file first read, fully cached into a memory and then saved as another file? Or is it the same as writing while read line; do echo "$line" >>...
0
votes
1answer
62 views

Curl a string with whitespaces and characters in it? [duplicate]

I'm trying to create a "simple" script that I'm going to use to create some documentation for Unix/Mac machines. I've successfully received the information I need, but it seems like I can't send it ...
5
votes
2answers
351 views

nested double quotes in highly-voted one-liner

A StackOverflow answer with > 3.5K votes features this one-liner for assigning to DIR the directory of the current bash script: DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" I'm ...
0
votes
0answers
40 views

tailing file in new terminal window

I have the following two bash scripts (perhaps they can be condensed into one). // pre-tail.sh #!/usr/bin/env bash open -b com.apple.terminal `dirname $0`/tail.sh // tail.sh #!/usr/bin/env bash ...
4
votes
2answers
40 views

Is it possible to print an iterated range of arguments via cli from a csv? (see example)

I have hundreds of logs spread across a few thousand VM's and I'm trying to create a few scripts to quickly scan logs and I have figured out the majority of the presentation and wanted to know if ...
-2
votes
1answer
43 views

Write shell script for logging in servers and run command after logging in

I have wrote a shell script for logging into servers and run few commands to start and stop processes running on it, So I tried below code, but it is showing error, please help me with the script. ...
2
votes
4answers
242 views

How to match “4.4” from `uname -r`?

Pseudocode [ `uname -r` =~ ^4\.4.*$ ] && echo "yes" which is, however, unsuccessful in all cases. The uname -r command gives things like 4.6.0-040600-generic as an output.
0
votes
1answer
29 views

What's the usage of rbash?

I've read some questions about the difference of TTY, console, terminal, etc here and on Askubuntu. Someone mentioned restricted shell, like rbash or bash -r. I first fought it is good to give ...
-3
votes
2answers
39 views

Apache log sorting most visited ip [closed]

cat access.log | grep -o "[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}" | sort -n | uniq -c | sort -n I don't understand this statement. Somebody please explain.
0
votes
1answer
44 views

help to analyse a log file

How does sed 's/\[//' work in case of analyzing log files for the time stamp fields? I found a solution online and I saw this line "$(head-1 "$1" | awk '{print $4}'| sed 's/\[//')". Can someone ...
1
vote
1answer
48 views

pass arguments to python program in shell

I am unable to run python script within a shell script. Following is the script.sh file where 3 arguments are being passed to the python script. python main.py 1.0 0.1 10 The python program is not ...
1
vote
0answers
24 views

Read a log file to extract various fields and count the occurance [closed]

I have a logger file like this: 2016-06-11 07:34:01.542 98459 [Thread-23-Job-parser-bolt] INFO JobLoader c.t.commerce.common.utils.APIUtils - Enrichment data updated successful for partnumber : ...
2
votes
2answers
126 views

Multiplying numbers in-place in a file

I have ASCII file contain numbers as follow: 1 2 3 5 6 9 7 8 9 . . . . . . . . . . . . . . . etc I want to upgrade this file by multiplying each value by "3" to get : 3 6 9 15 18 27 21 24 27 ...
1
vote
2answers
94 views

What exactly is terminal? What is shell? [duplicate]

I know about Linux terminal. I can also issue many advanced commands over terminal. But one simple concept is not clear to me. What is terminal and how does it work? I know about hardware which ...
0
votes
1answer
34 views

Read file upon .bashrc startup, based on date

I'd like to put a script in my startup that reads a line from a text file, and echoes this to the screen. However, I'd like a different line from the file based on what day of the month it is. Thus ...
-2
votes
2answers
62 views

Find all line in a file which start with g or any digit from 0to9

How do I find all lines in a file which start with g or any digit from 0 to 9? Can any one help me using command line? I try and I know how to do if start with g but don't know how to do with g and 0 ...
0
votes
5answers
103 views

how to iterate through files in directory excluding hidden files

Using: for eachfile in /mnt/thara/* Which iterates through hidden files as well. I don't need hidden files.
3
votes
2answers
66 views

obtain shell prompt in python

I want to obtain the (zsh) shell prompt in a python script. Simply using import os prompt = os.environ['PS1'] seems not to be the right way, because PS1 is usually not forwarded to subprocesses. In ...
1
vote
2answers
37 views

Shell shows I have mail, but how can I check it

When I startup the shell, it displays the message You have mail. and this is because I touched a file /var/mail/${USER} and wrote to it. But how can I check it? I use mail, but it shows me No mail ...
0
votes
1answer
22 views

Continue monitor web server and download newly added files

What are the best way to continuously monitor a web server (HTTP) and download newly added file with min. delay (ideally < 1min. delay)?
-1
votes
2answers
51 views

exit code from a builtin shell command [closed]

I'm writing a custom shell and I want to run a shell script with my own shell. I'm trying to check if the less program is installed and if it is, use the less program otherwise use more. However, my ...
0
votes
1answer
25 views

User Input Shell Script Syntax Error

I'm new to shell scripts and all, and wanted to write a script that would automatically perform this command for me: sudo aireplay-ng -0 (given number) -a (Router MAC Address) -c (Target MAC address) ...
1
vote
1answer
35 views

How to batch rename files by exchanging substrings in the filenames?

I have files like ABC_asd_f.txt, DEF_qwe_r.txt, ... How can I exchange the uppercases before the first underscore with the lowercases after? So ABC_asd_f.txt becomes asd_f_ABC.txt, DEF_qwe_r.txt ...
1
vote
1answer
28 views

.shinit vs. .shrc

When logging in to a Linux/Unix system via the old Bourne shell (sh), we have the .profile file to customize our environment for us. Some sources also reference either a .shinit file or a .shrc file. ...
1
vote
2answers
81 views

After small code change 'awk' prints header and blank lines, (not header repeated)

data-file content: k = 0.1667 0.0962 0.0000 ( 4922 PWs) bands (ev): -7.1689 -7.1043 -6.1682 -6.0658 1.1309 1.5196 3.0894 3.1087 3.3846 3.7588 4.2143 4.2220 4.3882 ...
0
votes
0answers
61 views

How to write Shell Script for Mongo Find query.?

i am new to Shell Scripting, Actually i am writing a shell Script for mongo to find specific document, this Shell Script Except a Argument and use in Find Query, So i had write a simple find query: ...
2
votes
1answer
30 views

Cannot stop bash to expand star (wildcard character) passed to app from shellscript

I have a shell bash script wich should pass the star ["*"] wildcard character to an application without using quotation marks. I am reading since hours and always find to use "set -f" inside the ...
2
votes
0answers
46 views

Network traffic monitor “nettop” morphing away from expected results

On Mac, I open a new shell and enter nettop. For a split second I see chrome (as I expected) and some other things going on (had to record screen to catch them); then I'm only shown data on ...
1
vote
1answer
67 views

Convert vertical array data to horizontal array data

I have a file with 25 matrices in a file, and each matrix is has 128 rows and 5 columns. Each matrix are putted one after the other, in a vertical way. Like this File input(file1): Array1 Array2 ...
2
votes
2answers
63 views

What is the best way to unlink hard-linked files?

Using rdfind I found a lot of hard-linked files (~60-90) and I want to unlink all of them. One possible solution is to just find all files -link +1 and just copy them, delete them and move it back to ...
2
votes
2answers
86 views

Use env with environment variables from file

Let's say I have a file (called e) with this content: a=3 b="5 6" How can I get each one to be interpreted as a separate argument to env? That is, to have it equivalent to: $ env a=3 b="5 6" ...
1
vote
1answer
42 views

Spawn command not found

I trying to use the spawn command to connect to remote server, execute some commands/script. Here is script: #!/usr/bin/expect for i in `srvctl status database -d PROD | awk -F " " '{print $(NF)}'` ...
1
vote
1answer
26 views

Group or world writable directory

I'm trying to use a script but get the following error: Directory is group or world writeable. This is insecure, since any malicious user can trick you to write newly generated private key into his ...
0
votes
2answers
47 views

How to fetch all the even lines and odd lines from a file and save them into two different files such as Evenfile & Oddfile? [duplicate]

The question is very simple. Suppose I've a file named "a.txt" and it has 100 lines. Now I want to extract odd lines i.e lines 1,3,5...etc and save them to a different file such as Odd.txt and the ...
0
votes
1answer
63 views

Weird user in shell

I use iTerm on OS X 10.10 When I start iTerm I get the weird user unknownA988274AC:~ myUserName$: That was not there before. Before there was myUserName$: Any ideas where that comes from?!
4
votes
4answers
44 views

Running multiple programs in the background and checking their return value

suppose I want to run a few (say, three) programs at once, like this program1 & program2 & program3 & if I want to know their pid's, I think the best way is to store them, like this ...
2
votes
2answers
70 views

Is there a way to route all commands through a shell script instead of running directly?

Sorry about the title, I can't explain it very well without an example. I want to be able to have everything being executed, rather than running the program, runs a shell script with the executable as ...
1
vote
1answer
37 views

cd to previous directories [duplicate]

I'm running CentOS 7, but hoping there is a general Linux way of doing this. So you can cd back and forth between the previous and current directory with this: cd - Is there I way can cd back ...
0
votes
2answers
115 views

How do I print 'block' letters in the terminal?

How do I echo/print block lettering in the terminal like: ? figlet and toilet don't help. Neither do U+25A0 or U+2588 unicode characters. This is not a duplicate. As I said, figlet, banner and ...
0
votes
0answers
30 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
61 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
488 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
51 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
68 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 ...