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)

1
vote
1answer
9 views

Read Multiple Entries from an Input File

I wrote a program in Fortran that asks me for latitude and longitude and the name of the output file every time I run it. It works great. What I have been meaning to do is run this program for the ...
0
votes
1answer
20 views

What is the term “Usage”?

I am seeing this a lot in the scripts. Is "usage" a command in unix ? I tried googling it but got ambiguous results. Here is an example : ${1?"Usage: $0 ARGUMENT"}
0
votes
1answer
33 views

Compare two strings in a shell script [duplicate]

My script needs two arguments. I want to hide the error message if someone calls the script with script.sh --help so I tired this: if [ $# -ne 2 ] ; then if [ "$1" -ne "--help" ]; then echo ...
0
votes
1answer
31 views

How to evaluate a variable length in shell script?

I want to write a shell script, in which it will call different command according to the variable length. But I didn't figure it out yet. My unwork script is here: for i in n5 n25 if ${#i} == 2; ...
1
vote
3answers
133 views

What is $() in a command?

What is $() in Linux Shell Commands? For example: chmod 777 $(pwd)
2
votes
1answer
16 views

Change the PS1 prompt in a subshell sh called from parent bash

When I am running an interactive bash session, I sometimes experiment with sh. I call sh directly from this bash session. My question is, how can I change the PS1 prompt of this subshell? I would ...
4
votes
0answers
41 views

How do I execute in background / return early?

For reference, I'm using phpseclib to control a remote SSH server using the 'root' account. I have to start/stop a java process which is ran in the background. Stopping works fine with killall java ...
0
votes
2answers
28 views

change boot order

I have 2 partitions sda1 XP and sda2 CENTOS. I have reinstalled grub on /dev/sda but on rebooting, I experienced: error : 22 no such parition for Centos; while Windows boots charmingly on the other. ...
0
votes
1answer
36 views

Answer password prompt programmatically via shell script

I would like to programmatically answer a password prompt using only shell script when prompted. Is it possible to automate this task in this way? I want to avoid other tools entirely - so no expect ...
1
vote
1answer
27 views

Recover files after moving directory names?

During the course of some testing, I ran the bast script for file in *; do mv -v "$file" "$file#_*" done or something along those lines. The plan was to remove a prefix from directory names ...
1
vote
2answers
48 views

If statement question

I am scratching my head to understand this script and can certainly use some expert advice. getopt_simple() { echo "getopt_simple()" echo "Parameters are '$*'" until [ -z "$1" ] do ...
4
votes
3answers
364 views

how to get the basename of complicated files [duplicate]

Here is an example of file path: /isf/GCM/VPfig/Aas/AR/ClCo el Doma Republic/VMN CRTro.txt What I want to get is the file basename: VMN CRTro.txt So I try the following: echo ...
2
votes
2answers
58 views

Ping multiple hosts and execute command

I'm very new in bash scripting and unix so I will need some help on this.I have 7-10 hosts which I want to ping from one of the servers via cronjobs. What I want is when host is up to execute command ...
0
votes
0answers
10 views

Chrome OS: Crosh Window and Hostname

I have a couple of questions regarding Chrome OS: By default Ctrl+Alt+T opens a crosh window within the Chrome browser. I have the Crosh Window extension, which I would like Ctrl+Alt+T bound to - ...
8
votes
6answers
361 views

How can I test if a variable is empty or contains only spaces?

The following bash syntax verifies if param isn't empty: [[ ! -z $param ]] For example: param="" [[ ! -z $param ]] && echo "I am not zero" No output and its fine. But when param ...
8
votes
3answers
202 views

Going into a directory linked by a link

When I cd a link, my current path is prefixed with the link's path, rather than the path of the directory the link links to. E.g. ~/dirlinks/maths$ ls -l logic lrwxrwxrwx 1 tim tim 71 Jul 27 10:24 ...
1
vote
1answer
35 views

regenerate xorg.conf with current settings

Many people have talked about this issue but I've not found a satisfactory answer. I'm on a debian jessie. Currently I have tried nvidia-driver as the driver but it caused the system to crash; so I ...
2
votes
1answer
44 views

Forward SIGTERM to child in Bash

I have a Bash script, which looks similar to this: #!/bin/bash echo "Doing some initial work...."; /bin/start/main/server --nodaemon Now if the bash shell running the script receives a SIGTERM ...
0
votes
3answers
53 views

grep substring between quotes

Let's say I have a string like this: title="2010-09-11 11:22:45Z" How can I grep the date itself and disregard the quotes/title/Z? The file can contain more strings like: randomstring ...
18
votes
2answers
693 views

Does ~ always equal $HOME

I know this has probably been asked before, but I couldn't find it with Google. Given Linux Kernel No configurations that change $HOME bash Will ~ == $HOME be true?
4
votes
1answer
110 views

Proper way to distribute shell scripts

What is the most proper way to distribute shell scripts, if behaviours of shells can be modified by set and thus are unpredictable? For example, rm *.txt wouldn't be executed as expected on the ...
4
votes
4answers
111 views

Check if content of file has length X and contains only specific characters

Let's say, I have files that contain only one docker id: myid.id: 28fe2baadbe8da32ed0b99c69b11c01b2d141bc5b732b81e0960086de52fc891 I want to check if the content of my.id is exactly 64 characters ...
2
votes
1answer
35 views

Arrow key/Enter menu

I need help finding out how to possibly create a menu in a shell script that will display 3 options that a user will use the arrows keys to move the highlight cursor and press enter to select one. If ...
5
votes
1answer
419 views

What does su - `whoami` command do?

I am running a script in my project and I see this command su - `whoami` I am having a few basic questions: What does this command do ? What is the significance of `` quotes outside the whoami ...
4
votes
2answers
121 views

sed to search for multiple words and remove those lines

I have a master file with more than 50000 lines and my requirement is to remove around 20000 lines from actual file, for this I used grep -vE command which is showing an error as too many arguments. ...
1
vote
3answers
53 views

List all the html tags in a file

I want to know if there is a way to list all the html tags in a file. Lets say I have a file file.html <html> <head> <title>Test</title> </head> <body> This is a ...
2
votes
2answers
52 views

Decoding “prog > file 2>&1”

I am having some difficulty understanding the construct prog > file 2>&1. I have read that it means "Send stdout and stderr to file". But my question is how? I understand that prog > ...
0
votes
0answers
54 views

Mirrored Linux Commands [closed]

I've encountered two incidents where commands (or logic flow) is given forward and backwards In bash scripts: if ... fi (use to closed an if-statement) and in GNU/Linux command line: cat; tac (cat ...
1
vote
0answers
15 views

Mirrored Linux Commands [duplicate]

I've encountered two incidents where commands (or logic flow) is given forward and backwards In bash scripts: if ... fi (use to closed an if-statement) and in GNU/Linux command line: cat; tac (cat ...
5
votes
3answers
180 views

How to remove dot and space from beginning of filenames

I'm trying to change jpg files named with a dot and a space at the beginning and with a missing dot before the end (like this . Startjpg to Start.jpg The dot makes the files hidden from sed and ls ...
1
vote
1answer
74 views

What Causes Maintenance Shell Segmentation Fault?

I'm running Ubuntu 14.04 Trusty Tahr in a Microsoft Hyper-V virtual machine on Windows Server 2012 R2. I've stopped the VM, replaced an EXT4-formatted virtual disk volume (/dev/sdb) with a new ...
2
votes
2answers
29 views

I seem to be “losing” this prompt. What is happening?

I ssh into an ubuntu 12.04 cloud server and start a web server like this (w/ bash): $ nohup python tserver.py & [2] 2122 $ nohup: ignoring input and appending output to `nohup.out' After I run ...
8
votes
3answers
334 views

Replace multiple spaces with one using 'tr' only

I have a file, f1.txt: ID Name 1 a 2 b 3 g 6 f The number of spaces is not fixed. What is the best way to replace all the white spaces with one space using only tr? ...
5
votes
2answers
65 views

How can I pipe stdout to another program?

I'm trying to setup a linter for my code and I only want to lint the coffeescript files that have changed in the current branch. So, I generate the list of files using git: git diff --name-only ...
2
votes
2answers
59 views

How to change my script to replace and add new variable in a configuration?

Well this is my script. It is to configure my systems sysctl.conf. infile = open('sysctl.conf') outfile = open('sysctl.conf.new', 'w') replacements = {'Net.ipv4.icmp_echo_ignore_all' :'1', ...
0
votes
1answer
38 views

Faillog - unsuccessful login count in Motd

I wish to include a count of failed login attempts whenever a user logs in. I've created: /usr/local/bin/dynmotd which contains #!/bin/bash FAILLOG=`faillog -u` echo -e " $FAILLOG " and ...
3
votes
2answers
27 views

How to build space separated, escaped full paths of files recursively matching glob?

I have a program which requires paths to files as arguments, which cannot be quoted and must not depend on working dir. Can this be done without chaining multiple xargs, tr, find, readlinks? Example ...
0
votes
1answer
16 views

paths for searching executables [duplicate]

My old xournal is 0.4.5, which is /usr/bin/xournal. I just installed a new version 0.4.8 by compiling from source to /usr/local/bin/xournal. When I call xournal directly from the terminal, it is the ...
3
votes
1answer
62 views

Is there a way to pass a variable from an awk statement to a bash function as an argument? [closed]

I am trying to look a for some specific values from (such as 1 or 4 and 2 or 3) a text file using an awk statement in a bash script. If this value is found in the file (within the awk statement), then ...
4
votes
3answers
244 views

awk with if statements

I am trying to print from a file using awk, but my output is empty. Here is my code so far accountNum=$1 while read -r LINE || [[ -n $LINE ]] ; do awk -F',' '{ if($1==accountNum) { print ...
14
votes
3answers
939 views

What does it mean to be “sh compatible”?

I've seen the phrase "sh compatible" used usually in reference to shells. I'm not sure if it also applies to the programs that might be run from within shells. What does it mean for a shell or other ...
9
votes
2answers
280 views

Strange difference between pwd and /bin/pwd

I added a symlink to the current directory with ln -s . aa. If I execute cd aa, and after that I executed pwd, the response is /home/sim/aa. But if I execute /bin/pwd it prints /home/sim (the current ...
3
votes
1answer
47 views

Grepping a variable

I've written a simple init script to start and stop a Python script as a service. I have to be explicit about the version of Python I'm running, because this is on a CentOS 5 box with Python 2.4 & ...
4
votes
3answers
126 views

Regex alternation/or operator (foo|bar) in GNU or BSD Sed

I cannot seem to make it work. GNU sed documentation says to escape the pipe, but that doesn't work, nor does using a straight pipe without the escape. Adding parens makes no difference. $ echo ...
2
votes
2answers
47 views

Renaming the files and move to other path

I need to rename the files given below and move to some other path 1234551abcde20140718023216001.txt.809047512.2014_07_07_13:47:44 000001abcde20140718023216001.txt.34568.001.2014_07_07_13:50:44 ...
4
votes
5answers
87 views

Add leading characters infront of string using printf or echo

How can I add leading characters to fill a string to a certain length? Assume I want to add zeroes infront of a string, if said string is shorter than 20 characters: printf '%020s\n' "$line" ...
0
votes
1answer
28 views

Must pass urls in quotes

I'm trying pass a URL to mpv for it to play it as a network stream. This can be done in bash with the following syntax: $ mpv http://myvideosite.com However, zsh wants to evaluate the URL as ...
1
vote
2answers
24 views

Shell is option given

I have a couple of arguments inside a list (array, e.g. $@) and I'd like to know if the option -v is in the list. In Python I would simply do: verbose = "-v" in sys.argv How do I achieve that in ...
2
votes
1answer
41 views

How can I get this script file's functions to load without having to source it every time? “command not found” (Bash/scripting basics)

How can I get this script file's functions to load without having to source it every time? I created a file foo with script functions I'd like to run. It's in /usr/bin, which is in the PATH. File ...
1
vote
1answer
53 views

Verify the length of a variable

I've to verify the length of variable read (my script limit to five the characters inserted), I think about something like this: #!/bin/bash read string check=${#string} echo $check if [ $check -ge 5 ...