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)

6
votes
1answer
572 views

Two pipes to one command

I am little bit confused by the following syntax. Although it works, It do not understand why it works. It seems, like there are two pipes attached to the diff command. But isn't there only one STDIN? ...
67
votes
27answers
14k 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 ...
4
votes
3answers
554 views

Is it possible to use split to make character chunks out of Chinese unicode bytes?

For a while, I've been dealing with Chinese unicode text. Of course, the usual rules apply. I can grep for characters the same way I'd do so for words. This is very useful to me. But there's one ...
2
votes
1answer
541 views

What is the significance of the “1” in ls(1)? [duplicate]

Possible Duplicate: What do the numbers in a man page mean? I see functions referred to with numbers in the parenthesis in documentation. What does this mean? It takes one argument? ...
11
votes
3answers
11k views

How to escape quotes in shell?

I'm having trouble with escaping characters in bash. I'd like to escape single and double quotes while running a command under a different user. For the purposes of this question let's say I want to ...
13
votes
2answers
5k views

In zsh how can I list all the environment variables?

I want to get a list of all environment variables (shell variables? exported variables?) and their values at a given time, in zsh. What is the proper way to do this?
4
votes
2answers
4k views

Running a command on the remote host with interactive SSH (conditionally)

I would like to be able to automatically run a command on a remote host each time I log into that host, but within the current interactive SSH session. Something like ssh user@remotehost [run do.sh] ...
4
votes
1answer
466 views

Efficient way of comparing in awk

#!/bin/awk BEGIN { while(getline var < compareTo > 0) { orderIds[var]=var; } } { if(orderIds[$0] == "") { print $0; ...
2
votes
1answer
473 views

How to create a book signature from text?

How can you transform a text file (plain text or HTML) or print-format file (PS or PDF) to bind it as a book using shell commands? That is, how do you create a print-format file which orders pages ...
3
votes
1answer
297 views

Can I copy text from one file by shell?

Can I copy text to the clipboard from one file by shell? and I want to paste it to Browser later.
2
votes
2answers
582 views

changing default shell to /bin/bash of at job scheduler like in CRON

I recently switched from 2>&1 >> to &>> Is there a way to have at use /bin/bash as the shell? By default it uses /bin/sh and the man page gives no indication how anything else ...
14
votes
2answers
1k views

What does `:-` mean in a shell script

I saw this in the end of an awesome shell script but I can't understand the login here because I think it's being short-handed for a longer command. spark ${@:-`cat`} This apears at the end of this ...
4
votes
2answers
171 views

check patterns that don't exist in sqlite

I explained a similar situation with plain text files on Grep huge number of patterns from huge file. Many people there said I should, so now I'm migrating my data to a sqlite database: I have a file ...
2
votes
2answers
359 views

Manipulating and saving multiple files

I have ~2k files that I want to extract 12 of 26 columns and save the extracted information into a new file. I have been doing this for individual files using cat "oldfile.csv" | grep -v "=" | cut ...
5
votes
2answers
349 views

Object oriented Unix shell with at least LINQ capabilities?

Well, "at least" is rather -- it would be perfect ;-) There is similar question -- Object-oriented shell for *nix . For me similarity with bash is no issue. I would like to have some simple OOP plus ...
44
votes
2answers
44k views

How to get the pid of the last executed command in shell script?

I want to have a shell script like this: my-app & echo $my-app-pid But I do not know how the get the pid of the just executed command. I know I can just use the jobs -p my-app command to grep ...
5
votes
3answers
328 views

Preventing binary planting attacks in Linux

If a user account on a Linux machine is compromised, clearly, all files owned by that user are compromised. Unfortunately, if the compromised user also has sudo privileges, it seems that binary ...
9
votes
1answer
6k views

How can I make variables “exported” in a bash script stick around?

I have multiple Amazon EC2 accounts and want to quickly be able to switch variables, such as $EC2_HOME, using a script. I have have a shell script set up like this: #!/bin/sh export ...
3
votes
2answers
1k views

How to add/replace only modified/updated files recursively for some 2 folders?

So I currently do stuff like: rm -rf ../../../$CLOUD_INSTALL_SUBDIR/lib_boost mkdir ../../../$CLOUD_INSTALL_SUBDIR/lib_boost cp -r ../../../$BOOST_ROOT_DIR/$BOOST_INSTALL_SUBDIR/lib/* ...
2
votes
1answer
912 views

skype not found on Oneiric 64, but it is right there [duplicate]

Possible Duplicate: Can't execute some binaries in chroot environment (zsh: Not found) I have something weird here. Cannot find a file although it is right there. $ skype command not ...
4
votes
2answers
651 views

Why does this shell snippet to check if hosts are up using netcat stop prematurely?

Q: Why does the second iteration exits after 10.175.192.16? Can someone explain that? Or I just found a "while/netcat" bug? a.txt's content: $ cat a.txt 10.175.192.14 10.175.192.16 10.175.192.17 $ ...
4
votes
2answers
296 views

Extract part of the first line of a file

I am trying to configure some external commands in Gedit3, for compiling LaTeX files. All works well, except for the following. I have a LaTeX document, consisting of many parts. Each file begins with ...
3
votes
2answers
908 views

Getopts option processing, Is it possible to add a non hyphenated [FILE]?

I'm using getopts for all of my scripts that require advanced option parsing, and It's worked great with dash. I'm familiar with the standard basic getopts usage, consisting of [-x] and [-x OPTION]. ...
9
votes
5answers
5k views

Shell Script mktemp, what's the best method to create temporary named pipe?

I'm aware its best to create temporary files with mktemp, but what about named pipes? I have an idea, I'm sure it would work, but I would really like an expert opinion. I prefer things to be as ...
1
vote
3answers
1k views

unzip a file from another folder

How can I unzip a file from another folder? gunzip -d /home/tomcat_dev/HN/radd/input.txt.gz unzips that file to the same folder. But if I want to bring it to my folder? When I do this: gunzip -d ...
1
vote
4answers
374 views

What does sdptool do in this script?

Here I want to know about this sdptool command does in the following script snippet: if [ `sdptool browse $BD_ADDR | wc -l` -lt 5 ] I understand sdptool browse $BD_ADDR as well as wc -l -- it's ...
9
votes
5answers
4k views

Randomly draw a certain number of lines from a data file

I have a data list, like 12345 23456 67891 -20000 200 600 20 ... Assume the size of this data set (i.e. lines of file) is N. I want to randomly draw m lines from this data file. Therefore, the ...
2
votes
2answers
3k views

Issues of using sort and comm

I was trying to find the intersection of two plain data files, and found from a previous post that it can be done through comm -12 <(sort test1.list) < (sort test2.list) It seems to me that ...
6
votes
4answers
6k views

How can I convert a .cue / .bin ( with cdr tracks) image into a single .iso file?

The title is descriptive as is: How can I convert a .cue / .bin (cdr track) image into a single .iso file? I have Fedora 16 (x86-64) Linux 3.1.9-1.fc16.x86_64 #1 SMP Fri Jan 13 16:37:42 UTC 2012 ...
7
votes
2answers
414 views

Continue shell commands once connected to SSH

Not sure if the question I'm asking is correct but basically I wanted to automate this process scp ~/.ssh/id_rsa.pub username@example.com:~/ ssh username@example.com mkdir .ssh cat id_rsa.pub ...
1
vote
2answers
513 views

cp does not copy new files of source location (files created after firing cp command)

I am using the following command to copy contents from a source directory to a destination directory: cp src/* dest However, after evoking this command and while when contents are getting copied, ...
9
votes
1answer
1k views

How to detect when a shell is owned by a remote SSH session?

My question is similar to this one, but I'm looking for something slightly different. I have a notebook PC that I use to access Linux machines on a network in two different scenarios: I have a ...
1
vote
3answers
2k views

rename multiple files with rename command? [duplicate]

Possible Duplicate: How can I rename a lot of files using a regex? Rename All Files with a Certain Name There are files with ORDER_EVENTS_SOMETHING_20120117.log ...
2
votes
2answers
491 views

Execute a command for each entry in a file

How can I execute a command for file which has address of jar files. The command that I want to execute is jar xf entry.jar. I d like to execute that command and sent the outputs to another file. ...
8
votes
4answers
2k views

how can a makefile detect whether a command is available in the local machine?

I began to use org-mode for planning out my tasks in GTD-style system. Putting every org files in a directory of a Dropbox folder, I run emacs to edit / manage these files from three different local ...
7
votes
2answers
209 views

Is it possible to make scp fail when you do a local copy?

Is it possible to make scp fail when you do a local copy? I find it annoying to accidently create files with names like 192.168.11.5 when I meant to type 192.168.11.5: and hence copying the file to ...
3
votes
3answers
2k views

How do I run a script n times at same time and how do I simulate a semaphore?

I have a text file, inside of this file is a number, and I have a script.sh in ksh. The script reads the file and gets the number, then increases the number by 1 and overwrites the new number in the ...
3
votes
1answer
586 views

ssh “-f” don't give back hand in bash when listening to stdout/stderr

Please look at these: ## Does NOT return to the shell, but Ctrl-C can exit ssh -S none -fNR 13018:localhost:22 example.com | cat ## Returns to the shell (no "-S none") ssh -fNR ...
5
votes
2answers
469 views

Can I trace a dash script without modifying its source code?

I would like to trace a shell script for debugging purposes without having to modify its source code (e.g. change the shebang or insert a set -x at the beginning). It is a dpkg postinst script, so not ...
3
votes
2answers
4k views

list the difference and overlap between two plain data set [duplicate]

Possible Duplicate: Linux tools to treat files as sets and perform set operations on them I have two data sets, A and B. The format for each data set is one number per line. For instance, ...
7
votes
2answers
3k views

List elements with spaces in zsh

I've been studying zsh scripting for all of 2 hours at this point and I've hit a wall. I want to go through a list of files that may have spaces in them. I'm open to completely different approaches ...
5
votes
4answers
8k views

What is the syntax of a complex condition in shell?

If want to express the following test in shell (sh) : if ( a == 1 && ( b == 1 || b == 2 )) { ... } So far, the best I have been able to write is this : if [[ $a -eq 1 ]]; then if [[ $b ...
2
votes
2answers
1k views

.sh file cannot be executed without explicitly calling sh

This problem has bugged me so much and I can't find a solution. Sorry in advance if it is a newbie question. Let's say I have a file called run.sh that contains: #! /bin/sh -x x-www-browser ...
1
vote
1answer
917 views

Execute command through SSH

I am writing a script to check whether all the servers in my organization are functioning properly. One of those is Zimbra mail server. I am trying to send a mail through sendmail provided by zimbra ...
8
votes
1answer
7k views

How to hide commands typed in a Linux shell?

Is there a way to hide what I'm typing in a shell, so the terminal doesn't echo my keystrokes, while still keeping the output of the command? For example, if I run ip addr show, the only thing on the ...
43
votes
5answers
29k views

How can I send stdout to multiple commands?

There are some commands which filter or act on input, and then pass it along as output, I think usually to stdout - but some commands will just take the stdin and do whatever they do with it, and ...
3
votes
3answers
680 views

Escaping argument in bash script?

I'm writing a bash script wherein I want to check that one of the arguments passed to it is a valid group. I have the line if [ `grep -c -e '\b$2\b' /etc/group` -eq 0 ]; then echo "Error: $2 is ...
16
votes
4answers
17k views

How can I install the `ll` command on Mac OS X?

I'm using Mac OS X. When I SSH into servers I find the ll command useful, but it's not available on my local machine. How can I install it?
1
vote
4answers
359 views

What is this Bash line supposed to mean?

find . -name "*.html" -exec grep -l somethingtobefound {} \; I was just wondering what the keywords "-name" "-exec" "-l" "{}" "\" and ";" were supposed to signify. Also, I commonly see ...
2
votes
5answers
4k views

script to scan ip range and return results in a certain format

This script scans IP's and returns a status of Up or Down. How can I alter it so it doesn't scan everything twice? As it sits it scans everything and returns the "Up" addresses only and then scans all ...