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
3answers
62 views

Rename directory from within directory?

How would I rename a directory from within that directory? For example: ~/tmp $ rn tmp2 ~/tmp2 $ I can do that with: cd .. && mv tmp tmp2 && cd tmp2, but not sure how to make it ...
2
votes
1answer
133 views

prevent trap from altering underscore variable $_

I have the following code in my bashrc to get the execution time of the last command from http://stackoverflow.com/a/1862762 function timer_start { timer=${timer:-$SECONDS} } function timer_stop { ...
2
votes
1answer
696 views

Hiding Command Messages in a Shell Script

In a bash script, I'm using tools like conntrack and tcpdump to output results to a file, but wish to hide the standard message displayed on the first output line on the command line after executing ...
4
votes
2answers
197 views

Why is $# always 0 in my function?

Bash is driving me nuts. I can't figure out why the following (nor any of the dozens of variations I've literally copied and pasted from examples) fails to work: #!/bin/bash echo $# function main { ...
2
votes
3answers
1k views

How to run a script after connected with ssh

I've heard multiple answers of rights and wrongs and I still don't know if its possible. I ssh to a server then want to run a block of script. while read server <&3; do #read server names ...
1
vote
1answer
100 views

ssh key authentication not working from network/if-up.d/ scripts

I have two nearly identical scripts in network/if-up that need to access SSH keys. Permissions on SSH private keys are 600, so how can my scripts access these keys? I would prefer to keep the SSH ...
2
votes
1answer
469 views

cat >/path/to/file <<EOF drops some paste content, also patch <<EOF too. Why?

From time to time I like to use cat >/etc/configfile <<EOF thing, and paste content, then send EOF that will flush it into file. Its good with one or two lines, but when there's more of them, ...
4
votes
3answers
2k views

Possible to get SMS/text message notification when process ends/is killed?

There are scripts that will send an e-mail when a server process is finished. However, I do not want to check my email every so often just to see whether a job has finished. Therefore I'd like to get ...
1
vote
2answers
281 views

Getting specific line from terminal output

"Hmm, I need to edit file-i-must-edit-2, but I cannot remember where it is." locate file-i-must-edit /home/user/file-i-must-edit-1 /home/user/file-i-must-edit-2 /home/user/file-i-must-edit-3 ...
1
vote
1answer
97 views

Find if a process terminates in a specific amount of time

I am running a program.Inside this program i run a specific command and i use ulimit command to terminate the running of that command if it exceeds an amount of time.To be more clear i run this: ...
14
votes
1answer
2k views

Delete all files starting with a question mark

I have a folder in which I have around 4k files. Some of these files start with a a ? or ! character. I need to delete them but can't find an expression that would do so: rm -f ./?* just deletes ...
0
votes
1answer
540 views

Using a file input as stdin for a shell script does not work

I have the following script code: test.sh echo "BEGIN" while read CMD <&1; do [ -z "$CMD" ] && continue case "$CMD" in start) echo "get_start" ;; ...
1
vote
1answer
300 views

Trouble with mv and adding the date

I want to be able to move $oldfile to my backup folder and add the date to the file name. So I tried this... mv $oldfile /home/u0146121/backupfiles/$oldfile_$(date +%F-%T) This just gives me this ...
3
votes
2answers
1k views

How to prevent command injection through command options?

I have an wrapper application where I need to let the user specify custom options to pass to a simulator. However, I want to make sure the user doesn't inject other commands through the user options. ...
2
votes
1answer
709 views

Gnome + Linux: GUI apps don't inherit PATH from parent console apps

In Gnome, don't GUI applications inherit the PATH of the shell process that launches them? Apparently, GUI applications see only the PATH specified in ~/.profile. No issues with console applications, ...
4
votes
1answer
545 views

How can I use tee and logger -t “some tag:”?

I've seen in another post which shows how to use tee and logger as shown below. tee >(logger) <<< "System Load is OK : $Current_loadadv" >(logger) is bash syntax to create a file ...
-1
votes
1answer
433 views

Tab autocomplete for files with spaces in it [closed]

How do I tab autocomplete for files with spaces in it? Thanks.
0
votes
2answers
3k views

Read the output of a command into a variable [duplicate]

I am making a bash script but I'm totally new and got lost. I've made this code cat * | grep "|*parameter1*|" | grep "|*parameter2*|" | cut -f 8,11,12,15,21,23,34 -d "|" | wc -l which works just ...
2
votes
2answers
1k views

How to download the latest file in a folder using a scp?

I'd like to run an scp transfer to download the latest (newest) file in a certain directory to my local directory. Something like this: source: root@rimmer.sk:/home/rimmer/backups/ destination: ...
1
vote
1answer
319 views

Can't access command history in my shell (sh)

I'm not sure if readline is what really missing but the problem is shell (instead of bash) and when I click the up and down arrow I get the following instead of command history: $ ...
1
vote
2answers
94 views

how to count number of differences in large streams quickly?

I want to count the number of differences (different bytes) in two large streams (devices/files). E.g. two hard disks, or one hard disk and /dev/zero. The program(s) involved must be fast, as fast ...
10
votes
2answers
351 views

What is the difference between “*.pl” and *.pl in grep? Why does quoting change the result?

What is the difference between: grep "string" . -r --include *.pl and grep "string" . -r --include "*.pl" The latter includes files in subdirectoried while the former not. Why?
4
votes
1answer
107 views

How to concat file and a line on-fly?

I would like to send to the stdout entire file + extra line. How to do this nicely? So far I did: for LINE in $(cat $INPUT_FILE) do echo $LINE done echo $EXTRA_LINE How to do this bash way (for ...
0
votes
2answers
359 views

How can I make “bind” command to work in sh shell

How can I make the next script to run when I'm using sh shell: #!/bin/bash bind '^[[3'=prefix-2 bind '^[[3~'=delete-char-forward bind '^[[1'=prefix-2 bind '^[[1~'=beginning-of-line bind ...
2
votes
2answers
476 views

Bad substitution inside xargs subshell?

I'm using this command to process PNG files: find . -iname "*png" -print0 | xargs -r0 --max-procs=4 -n1 sh -c 'pngnq -s1 $1 && advpng -z -4 -q ${$1%.*}-nq8.png' - It seems to actually work ...
1
vote
1answer
163 views

Delete key doesn't work properly in PHP interactive shell

In the interactive shell oh PHP Delete key is not working and produce ~ instead. Anyone know how to get this key to work? I am using Ubuntu 13.04 if this does matter.
0
votes
3answers
242 views

Renaming all files in a directory while keeping the same initial part of the name [duplicate]

I have a directory full of files. I want to rename all the files that match *.py to -backup.py. How do I do that. I know I can use for i in *.py, but from there I'm not sure how to keep the ...
2
votes
1answer
213 views

how do I reference a variable in fish shell with a default fallback

What is the fish shell equivalent to the following bash: echo ${TEST:-1} In bash this would print the value of TEST if there was one, or 1 if there was not.
26
votes
4answers
2k views

How to go to the previous working directory in terminal?

In terminal, how can I define a key to go to the previous directory which I was in when changing directory with the cd command? For example, I'm in /opt/soft/bin and I cd into /etc/squid3 and I want ...
1
vote
2answers
299 views

Use a different shell by default in each terminal emulator

I would like to change the default shell in each terminal emulator separately. To clarify, I want Xterm to use TCSH, pterm to use pysh, gnome-terminal to use BASH, etc. Is this possible? If so, how ...
2
votes
1answer
142 views

Change the default shell to Python

If I changed my default shell from BASH to Python3 or IPython, would my Linux system have issues or produce errors?
3
votes
3answers
2k views

How to stop redirection in bash

I use : exec >script.log 2>&1 in my script to redirect all output to a file. At the end of the script I would like to print a message to the screen. How do I stop the redirection?
3
votes
3answers
6k views

change shell in Solaris/SunOS for your user only wihtout access to /etc/passwd

How do I set the shell in Solaris/SunOS for my user only, without access to /etc/passwd or any other su stuff? It should thereafter work both for interactive ssh (1) and ssh when you send commands ...
0
votes
0answers
19 views

C Shell Array Declaration Syntax, () vs. {} [duplicate]

In my C-shell script (tcsh specifically) I have been trying to declare an array with six values: x, nx, y, ny, z, nz. After some trial and error I discovered three different ways of declaring the ...
4
votes
5answers
199 views

Standard unix util to split “foo.bar.baz” into “foo.bar” + “.baz”?

I want to split a string $basename, containing the output in two parts, $stem and $ext, such that: the string "${stem}${ext}" is identical to the original string $basename; either $stem or $ext may ...
3
votes
2answers
1k views

How do I run a command on multiple files

This is pretty basic, I have a folder with several subfolders of JS files and i want to run Google's Clojure compiler on all of the files in those folders. The command to process a single file is as ...
16
votes
4answers
4k views

Why does `cd` command not work via SSH?

I was trying to backup some files via SSH but instead of tar'ing the ones I wanted I got my home folder. I did some further testing and it boils down to this: ssh root@server /bin/sh -c "cd /boot ...
1
vote
4answers
310 views

Command substitution grepping ls output causes error

I'm trying to make a tar.tgz file using command substitution There are backups of 17 Aug 2012 -rw-r----- 1 ossec 502 804M Aug 17 2012 BKPMDISINT_i6nir20j.F_bkp -rw-r----- 1 ossec 502 2.7G Aug 17 ...
9
votes
2answers
6k views

how to output text to both screen and file inside a shell script?

Currently I have a shell script which logs messages to a log file like this: log_file="/some/dir/log_file.log" echo "some text" >> $log_file do_some_command echo "more text" >> $log_file ...
4
votes
1answer
4k views

Redirect both stderr and stdout to /dev/null with /bin/sh

Tried all sorts of ways to redirect both stdout and stderr to /dev/null without any success. I have almost my entire life run bash which i've never had this issue with but for once in BSD i'm stuck ...
2
votes
1answer
778 views

Use the terminal's autocomplete path feature for input to a shell script

I want to make a script that: (1) Gets a path giving the user the ability to use tab to autocomplete, then (2) gets a filename from the user, and then (3) creates a file at that path with extension ...
4
votes
3answers
2k views

How do I run a shell command from .tmux.conf

How do I run a shell command from .tmux.conf, or otherwise automatically when tmux launches, without having to hit any other command? How can I create an alias, a function, or a script which boils ...
1
vote
1answer
572 views

How to filter an array of strings in ksh

Please advise what's wrong in my ksh code. I want to remove the IP's as defined in "bb" array from "aa" array so the IP's 255.0.0.0 and 255.255.255.0 will be removed from the list in aa array. When ...
19
votes
3answers
844 views

Show PATH in a human-readable way

I want to show my PATH environment variable in a more human-readable way. $ echo $PATH ...
5
votes
3answers
83 views

How can I remove a file called “--help” with bash command line? [duplicate]

I've somehow managed to create a file with the name "--help". If I try to remove the file using "rm" funny stuff happens. Please help here's a printout of the dir listing: [pavel@localhost test]$ ls ...
1
vote
1answer
257 views

I quite like mercurial .hgignore-style globbing. Is there a Linux shell that supports it?

I quite like mercurial .hgignore-style pattern globbing. Globs are rooted at the current directory; a glob such as *.c will only match files in the current directory ending with .c. The ...
3
votes
2answers
142 views

Cron job for every minute executing out of order?

I'm setting up some shell scripting to be executed every five minutes, then every minute on our client's system, to poll a log and pull some timing information to be stored and accessed by another ...
7
votes
3answers
4k views

how to count total number of words in a file?

I am looking for a command to count number of all words in a file. For instance if a file is like this, today is a good day then it should print 5, since there are 5 words there.
4
votes
3answers
797 views

Reading a binary file as an array of bytes or 16 or 32 bits using shell script

I am working on ARM-based modem Linux host machine and I need to read a bin file as an 8-,16- or 32- bits array. I basically need to encrypt the file in question and was thinking of just XOR-ing the ...
1
vote
3answers
661 views

how does built in commands of a shell implemented in Linux? as a function or thread of shell process?

I know that external commands are run in the shell by creating a separate process. But what exactly happens when a built in command is run in a shell. Are they executed as a function or if the shell ...