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
1answer
26 views

Background a process and execute something with one command

Probably it would be easier to do just with a script, but I wonder why can't I do that with one command. What I have tried so far: $ (ls >/dev/null &) && echo $! 3135 $ (ls ...
1
vote
1answer
10 views

Check which RPMs depend on this package

I want to get a list of packages which depend on requested package. For example, I want to get all packages, which depend on telnet. I came up with this script: for i in `rpm -qa | sort`; do rpm ...
17
votes
9answers
7k views

Object-oriented shell for *nix

Preface: I love bash and have no intention of starting any sort of argument or holy-war, and hopefully this is not an extremely naive question. This question is somewhat related to this post on ...
2
votes
2answers
42 views

does sudo always set process limits to the numbers from /etc/security/limits.d?

I have observed the following behavior: [ec2-user@ip-10-66-68-55 ~]$ uname -a Linux ip-10-66-68-55 3.4.103-76.114.amzn1.x86_64 #1 SMP Fri Sep 12 00:57:39 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux ...
1
vote
1answer
49 views

How to restart my server automatically using crontab if they went down?

I have a jar file which I am running like this in my Ubuntu 10.10 and then it starts my exhibitor server in the background - nohup java \ -jar ...
3
votes
4answers
20k views

How do I exit or cancel a bad bash command?

I expect to get some flak for this, but I can't find the answer anywhere. It seems like it should be so obvious. Sometimes, when I type a bad command in a bash terminal, the cursor just jumps down to ...
0
votes
2answers
27 views

How to launch «gdbserver» in background?

I am communicating with a device via a serial port, and for I am launched «gdbserver» (like gdbserver :2345 myapp) it completely blocks the terminal. Neither an ampersand & symbol, nor ^z ...
0
votes
1answer
50 views

Shell string escape for command arguments [duplicate]

I'm trying to create "/tmp/pwet/foo bar" with this: DIR="/tmp/pwet/foo bar" ARGS="-p ${DIR}" mkdir $ARGS For integration reasons, I have to keep the ARGS building in 2 steps: ARG = some_options + ...
3
votes
2answers
38 views

echoing basename under xargs?

I have the following command : ls /some/path/*dat | xargs -n 1 -I @ sh -c "echo `basename @`" with the directory /some/path/ containing : /some/path/a /some/path/b /some/path/c /some/path/d I ...
2
votes
1answer
68 views

grep of a shell variable finds nothing

I have some problem with grep. I wrote a script which need to find some numbers from a list (file name ContigsNames) in a database. I wrote the following script: file=ContigsNames while IFS=' ' read ...
61
votes
25answers
10k views

Quick directory navigation in the terminal

I would like to frequently switch between directories that are in totally unrelated paths, for example /Project/Warnest/docs/ and ~/Dropbox/Projects/ds/test/. But I don't want to type cd ...
14
votes
4answers
2k views

What does echo $-1 display?

What does the output of echo $-1, echo $-2, echo $-3.. mean? On one of my Linux boxes, it shows me: echo $-1 imsBEl1 echo $-2 imsBEl2 And on another Linux box, it shows: echo $-1 himBH1 echo $-2 ...
1
vote
0answers
44 views

Cannot add startup service to openWRT from init.d

I have openWrt installed on a TP-Link TL-WA901N/ND v3. I don't have luci package installed because I don't have enough space, so I can only do thing via cli. What I'm trying to achieve is to create a ...
-1
votes
3answers
55 views

what is the use of '<<' redirection? [duplicate]

I am looking for an example of << redirection because i don't understand it well. I know < is for sending the contents of specified file to be use as standard input like : cat < file.txt ...
2
votes
3answers
74 views

Repeat Last N commands [duplicate]

In bash, I tried writing a script to run the last N commands. For say, N=5 for i in {1...5} do !-5 done The problem is that !-5 gets replaced by the 5th-last command on my shell (say time) and ...
2
votes
1answer
131 views

Shell script, find -name, and wildcard expansion

I'm trying to use find -name in a sh script with a previously computed complex argument for the condition. Simplified, it goes like cond="-name '*.txt*" find . $cond -ls But now I have the problem ...
17
votes
4answers
25k views

What does ` (backquote/backtick) mean in bash?

I came across the following command sudo chown `id -u` /somedir And I wonder what is the meaning of the ` symbol. I noticed for instance that while the command above works well the one below does ...
2
votes
4answers
6k views

How to login as root from Bash and do stuff

This is my simple bash: cat test.sh #!/bin/bash echo "hello" su - root -c /path/to/script.sh <<EOF password EOF whoami echo "good bye" But I get this error: ...
2
votes
1answer
28 views

Problem with install command to copy a whole directory

So I have a repo with some of my config files and I'm trying to create a makefile to install them in the homedir. The problem I have is that when I run the following command straight in bash install ...
2
votes
1answer
26 views

Strange leading whitespace in OPTARG when using getopts

I spent quite a while researching the problem I encountered but none of the getopts tutorial say anything about the leading whitespace in OPTARG when using getopts. In bash(on Ubuntu and OSX), ...
1
vote
2answers
530 views

Changing user to root when connected to a linux server and copying files

My script is coded in a way that doesn't allow you to connect to a server directly by root. This code basically copies files a server to my computer and it works but I don't have access to many files ...
8
votes
3answers
12k views

Why doesn't my ~/.bash_profile work?

I'm using Linux Mint. My login shell (cat /etc/passwd | grep myUserName) is bash. After I start my graphical desktop environment and run terminal emulator from it, I could see that .bash_profile is ...
1
vote
2answers
40 views

How to convert time from local timezone into Sydney timezone using korn shell?

I need to convert time from localtimezone (CET/CEST) to Sydney timezone (AEDT/AEST). I tried something like this: export date=$(date "+%Y-%m-%d %H:%M:%S AEDT") date "+%Y-%m-%d %H:%M:%S %Z" -d "$date" ...
0
votes
0answers
63 views

Why isn't this `expr … | bc -l` command working?

I'm noticing an error: bash: syntax error near unexpected token `-105.5*7+50*3' When executing the below script/expression: expr (-105.5*7+50*3)/20 + (19^2)/7 | bc -l Is there any other way ...
4
votes
3answers
79 views

Arithmetic operations with expr and variables

Why won't this statement work? total=`expr $mPercent / 100 "*" .482 + $fPercent / 100 "*" .518` mPercent is a number as a result of an awk statement, as well as fPercent. I also get "expr: ...
3
votes
7answers
207 views

get parts of string using shell script

I have one string as /ip/192.168.0.1/port/8080/ I want to get two separate variables which will contain port and IP like. 192.168.0.1 and 8080 as I know /ip/ and /port/ will be there always I ...
2
votes
2answers
44 views

Global Shell Variables?

As a system administrator with root access on a unix machine, is it possible to provide default shell variables to all users of a system? That is, as an individual unix user, I can define ...
1
vote
1answer
42 views

Installing packages on multiple Centos machines

I have to install standard package like java 1.7 in 40 of my lab machines which are connected over a LAN. I know I can simply write a shell script to install something in user space of each system, ...
1
vote
1answer
49 views

“Pipe” command to new bash shell?

I want to add my private key to the ssh-agent and I'm following these instructions. According to this the command ssh-agent bash spawns a ssh-agent bash and I can add my key afterwards using ...
0
votes
1answer
49 views

Unix shell script for server alerts

Below is my shell script which is written in another x to find the health of server y. ( I have not written in server y because there is no functionality of getting mails) #!/bin/bash ...
26
votes
3answers
34k views

How to suspend and bring a background process to foreground

I have a process originally running in the foreground. I suspended by Ctrl+Z, and then resume its running in the background by bg <jobid>. I wonder how to suspend a process running in the ...
1
vote
1answer
76 views

Jenkins does not use system's locales

I got a interesting behavior in Jenkins. Jenkins' shell does not use my systems locales. Jenkins runs as user jenkins on my system. Logged in as jenkins via SSH: locale displayed: ...
0
votes
1answer
49 views

How can a script ask me questions?

I am using this script to analyse data: #!/bin/bash in=/autofs/cluster/transcend/mega/scripts/ insub=/autofs/cluster/transcend/mega/dtn/20141015/123 out=/autofs/cluster/transcend/mega/scripts/1256 ...
3
votes
5answers
102 views

List files with line count and date

I want to be able to list files showing the number of lines the each file has and the date. I can happily get the line count using wc -l *. Not a problem. I can get the date using ls -l. Is there a ...
1
vote
2answers
54 views

Combination of echo, pipe and cat

I have a file name called temp.csv in my script one of the intermediate step is echo "some info" > final.csv | cat temp.csv >> final.csv at times the file final.csv is created without ...
26
votes
1answer
1k views

Why can Shell builtins not be run with capital letters but other commands can?

Why is this? When I do this CD ~/Desktop It doesn't take me to the Desktop. But this: echo "foo bar" | GREP bar gives me: bar
4
votes
1answer
2k views

Which shell should I learn for FreeBSD and Debian?

I have read many articles that say the official shell in FreeBSD is tcsh, and in Debian, its dash. However, when I either echo $shell (FreeBSD) or env in Debian, it says that the shell is csh in the ...
1
vote
2answers
124 views

Why are UNIX shells like this and how can I work around it?

One of the things I've noticed about BASH and other UNIX shells is that, by default and when used in typical ways, they spawn subshells for almost everything. e.g. foo=$(grep "someword" ...
5
votes
4answers
262 views

sed ranges aren't always able to match only one line

Consider the following range: 1,/pattern/. If pattern matches on the first line, the range matches for the whole file: $ cat 1.sh #!/usr/bin/env bash set -eu seq 1 4 | sed -rn '1,/'"$1"'/p' $ ./1.sh ...
5
votes
2answers
392 views

How to treat strings with spaces as a whole in bash? [duplicate]

I'd like to build an error handler which will make an empty file marked with the error_occur time. The core idea is to use the result of date command as a parameter. I did: time_stamp=$(date) touch ...
3
votes
3answers
216 views

How do I find a file with a name which depends on the current date (and a random component)?

I have to check a particular path every day and find the file with a name of the form: StaticData_Sets_yyyymmdd-232550.txt The date in the name after the string StaticData_Sets_ is updated every ...
10
votes
4answers
760 views

How to assign space-containing values to variables in bash using eval

I want to dynamically assign values to variables using eval. The following dummy example works: var_name="fruit" var_value="orange" eval $(echo $var_name=$var_value) echo $fruit orange However, ...
2
votes
5answers
225 views

Why do newline characters get lost when using command substitution?

I have a text file named links.txt which looks like this link1 link2 link3 I want to loop through this file line by line and perform an operation on every line. I know I can do this using while ...
0
votes
1answer
44 views

Why does “redirect to a file” is executed as user, even with sudo? [duplicate]

I often encouter this problem and it really bugs me on why it is so. So let's take this example into account : [me@localhost:~]$ sudo command > /some/file.log As far as I know, this will not ...
4
votes
4answers
4k views

Ctrl-C with two simultaneous commands in bash

I want to run two commands simultaneously in bash on a Linux machine. Therefore in my ./execute.sh bash script I put: command 1 & command 2 echo "done" However when I want to stop the bash ...
9
votes
4answers
3k views

Why is SIGINT not propagated to childs process when sent to it's parent process?

Given a shell process (e.g. sh) and it's child process (e.g. cat), how to simulate the behavior of CTRL+C using the shell's process ID? This is what I've tried: Running sh and then cat: ...
-5
votes
1answer
90 views

Extract multiple lines from text file [closed]

Source : ! hostname RTR-1 ! boot-start-marker boot-end-marker ! logging buffered 64000 informational no logging console ! interface FastEthernet0/0 description LAN ip address 172.16.29.250 ...
2
votes
2answers
41 views

Clear or disable aliases in zsh

I installed oh-my-zsh to make terminal use a bit easier. One thing that bugs me though is the prolific aliases added by it, like "ga", "gap", "gcmsg", "_", which are harder to remember than the ...
2
votes
1answer
1k views

Why the behavior of while loop and for loop is different?

I am trying to read user and server details from file tempo.txt and then check the disk space usage of the file system on that unix account using another script server_disk_space.sh.But I am not able ...
1
vote
1answer
58 views

Why is the result of this for and while loop different? [duplicate]

I have a for loop: for host in $(cat ./hosts) do echo -e "$host" ssh -o "StrictHostKeyChecking no" $host "uptime" 2>/dev/null echo -e "\n" done and a while loop which is supposed to the ...