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)

3
votes
1answer
32 views

What is the purpose of the uucico shell on HP-UX, Solaris, and possibly other Unix varieties?

For my work, I review Unix and Linux server configurations for compliance with security guidelines. So I'm not a Unix admin myself, but I work with Unix servers on a regular basis and am fairly ...
0
votes
1answer
19 views

bash-like last command in history using up-down arrow keys in zsh [duplicate]

In bash, we can use the up and down arrow keys to get the last or nth previous command in history. Can we do this in zsh?
8
votes
4answers
179 views

dirname and basename vs parameter expansion

Is there any objective reason to prefer one form to the other? Performance, reliability, portability? filename=/some/long/path/to/a_file parentdir_v1="${filename%/*}" parentdir_v2="$(dirname ...
2
votes
2answers
55 views

Set awk array on command line?

I know the -v switch can be used to awk on the command line to set the value for a variable. Is there any way to set values for awk associative array elements on the command line? Something like: ...
9
votes
2answers
520 views

Shell namespaces

Is there a way to source a shell script into a namespace, preferably a bash shell script but I would look into other shells if they had this feature and bash didn't. What I mean by that is, e.g., ...
-1
votes
0answers
12 views

List all files in USB device from /Volumes shell script [duplicate]

To clear things up I have setup folder actions on my mac for whenever a USB device is plugged into my mac it will run a shell script. When I list all files in the Directory /Volumes i get $ ls -a . ...
6
votes
3answers
12k views

Case-insensitive substring search in a shell script [closed]

How can I write bash code that will do a case-insensitive substring match of command output?
5
votes
5answers
17k views

How to catch an error in a linux bash script?

I made the following script: # !/bin/bash # OUTPUT-COLORING red='\e[0;31m' green='\e[0;32m' NC='\e[0m' # No Color # FUNCTIONS # directoryExists - Does the directory exist? function directoryExists ...
8
votes
1answer
419 views

How to find out whether a shell script is written in bash or sh

How can I find out whether a script is written in bash or sh? The first line of the script is not helpful here, since on Linux, bash scripts have this line: #!bin/sh Actually, there are many ...
11
votes
3answers
980 views

Why does set -e not work inside () ||

I've run across some scripting like this recently: ( set -e ; do-stuff; do-more-stuff; ) || echo failed This looks fine to me, but it does not work! The set -e does not apply, when you add the ||. ...
0
votes
1answer
23 views

regarding recursive deleting of a specific file type

I wanted to delete a specific file type say *.bak file from any directory and its subdirectories. I used the following command to find the files. find <path> -name "*.bak" -type f However, ...
77
votes
30answers
22k 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 ...
0
votes
3answers
41 views

How to put variable in for loops? [duplicate]

for seq in {046725..046899} do #body done Above segment of code runs beautifully keeping preceding zeroes in seq variable but why following code segment doesn't run? Is there any way? I need seq ...
3
votes
3answers
173 views

move middle part of filename to front

I have files named in the style 02.04.11 DJ Kilbot.mp3 (for several dates) and I want to reformat the name in this manner: DJ Kilbot 2011-02-04.mp3. In other words, the current format is MM.DD.YY ...
3
votes
3answers
42 views

How to treat numbers starting with zeroes as decimal integer

Input would be file name like following : A-B-000001-C A-B-000002-C ..... ..... A-B-999999-C All file should be sequential. I want to find missing sequential file names. For this I'm separating 6 ...
1
vote
3answers
36 views

What does the option -9 mean for killall?

I saw the command killall -9 but there is not such a option in the man page. So now I'm a bit confused: what does -9 option mean?
33
votes
1answer
3k views

Does 'rm .*' ever delete the parent directory?

The expression .* is expanded by bash to include the current and parent directories: $ ls -la total 2600 drwxrwxrwx 2 terdon terdon 2162688 Sep 10 16:22 . drwxr-xr-x 142 terdon terdon 491520 Sep ...
0
votes
1answer
29 views

Kill process with timeout

I want to start a programm with timeout, how can I kill the process using SIGINT and SIGKILL? If the programm not terminate within 5 seconds, send SIGINT. If it’s still running after 10 seconds (in ...
0
votes
2answers
35 views

Use a shell variable with Awk

I have this: if [[ $1 = "-c" ]] && [[ $2 =~ ^[a-z A-Z]+$ ]] then awk -v var="$2" '{print $2}' something.txt fi What I want is with a comand like -c abc to show the lines in something.txt ...
-1
votes
1answer
29 views

How is a trace of commands different from shell input lines?

I am unclear about two options when invoking a bash shell process or for set: -v Print shell input lines as they are read. -x Print a trace of simple commands, for commands, case commands, ...
0
votes
1answer
39 views

Get the external IP address in shell without dig in 2016?

This question: "How can I get my external IP address in bash?" Solves the question with a call to dig: dig +short myip.opendns.com @resolver1.opendns.com; that is the fastest resolution possible, ...
56
votes
9answers
94k views

How can I get the size of a file in a bash script?

How can I get the size of a file in a bash script? How do I assign this to a bash variable so I can use it later?
2
votes
4answers
1k views

How to subtract two times in shell

I nee to subtract two lines which is in the format of time in shell. The time format is hh:mm:ss I used the code below to get the time. cat /var/log/kern.log |grep usb |tail -2| awk '{print $3}' ...
0
votes
1answer
20 views

How to set up a pre-defined variable with multiple directory paths to use with the find command

I am looking to have a script delete files that are older than 90 days in certain directories. As in, there are 8 directories that have different paths to them. I can run the find command on one ...
0
votes
1answer
32 views

Parenthesis on echo shell command

I have this echo command: $ echo "alias notepad++="C:/Program\ Files\ "(x86)"/Notepad++/Notepad++.exe"" >> ~/.bashrc As shown in the picture it does not recognize the parenthesis.
0
votes
1answer
1k views

openSuse, not running the cron job

I have created a cron job in the /etc/cron.d/dispatchingEmail_I the permissions of dispatchingEmail_I are the following: -rw-r--r-- 1 root root 84 Sep 11 19:52 dispatchingEmail_I content of ...
4
votes
2answers
3k views

How to make cd arguments case INsensitive?

Sometimes while accessing the various directories it happens most of the times that I remember the names or at least part of the names of a directory under our Linux system. But some of the ...
1
vote
2answers
48 views

Invoking a script with sudo ignores the shebang

Invoking a script using sudo ignores the shebang and runs the script in a different shell. To test, I created a script (test.sh) containing: #/bin/bash echo "BASH is: $BASH" echo "actual shell is: ...
5
votes
4answers
593 views

list graphical processes from terminal

Do no confuse the question here with how to list processes graphically, that is not what I am asking. In the Terminal, how can i see which processes have a GUI? as in things like firefox, vlc, ...
2
votes
2answers
53 views

SOLVED: Shell Script cant run man command

I have a script that runs commands & takes a screen shot. I want the man file to display & grab a screen shot of it. My script works for the commands alone but if I add "man " before the ...
2
votes
3answers
1k views

How can I replace bash with Python?

According to the accepted answer for this SO question: , Python can make a great bash replacement. My question then, is this: how do I go about seamlessly make the switch? I think the main thing to ...
10
votes
4answers
817 views

Why doesn't echo called as /bin/sh -c echo foo output anything?

For example, while this works: $ echo foo foo This doesn't: $ /bin/sh -c echo foo Whereas this does: $ /bin/sh -c 'echo foo; echo bar' foo bar Is there an explanation?
7
votes
10answers
25k views

Bash way to check if a process is already running in the background (and skip re-execution based on that)?

Can I make a bash command line that only runs a certain command if the process is not already running (in the background)? How do I check*, if a command is already running? (so I can add the next ...
2
votes
3answers
2k views

Using sudoers to allow php to run command

I am trying to get my php page to run this command: shell_exec("sudo /home/xbian/433Utils/RPi_utils/codesend {$num}"); So I added this entry to my sudoers file with visudo: www-data ALL=NOPASSWD: ...
48
votes
7answers
9k views

Is there a one-liner that allows me to create a directory and move into it at the same time?

I find myself repeating a lot of: mkdir longtitleproject cd longtitleproject Is there a way of doing it in one line without repeating the directory name? I'm on bash here.
23
votes
3answers
12k views

bash multi line command with comments after the continuation character

Consider echo \ # this is a comment foo This gives: $ sh foo.sh # this is a comment foo.sh: line 2: foo: command not found After some searching on the web, I found a solution by DigitalRoss on ...
47
votes
2answers
16k views

Prepending a timestamp to each line of output from a command

I wish to prepend a timestamp to each line of output from a command. For example: foo bar baz would become [2011-12-13 12:20:38] foo [2011-12-13 12:21:32] bar [2011-12-13 12:22:20] baz ...where ...
0
votes
1answer
28 views

How to run command after entering postgres

I am trying to execute ls after opening a new Guake tab and logging into postgres. guake -n guake -e 'sudo -i -u postgres && ls' The command successful opens a new tab then prompts me for ...
0
votes
0answers
20 views

How do I execute a command if a drive is not mounted?

I am trying to create a shell script to mount a LUKS volume if it is not already mounted. The LUKS password will be in the shell script. The shell script is being stored in a encrypted folder so it is ...
35
votes
9answers
6k views

Output “Hollywood-hacker-scene” from a shell

This might seem like a strange question, but what would you use for creating the typical hollywood hacking scene? I got this request from a friend and my brain was blank. All I could think of was ...
4
votes
2answers
99 views

CInt Configure Script: Syntax error at left parenthesis

I am trying to install CInt. When running ./configure, I get the following error: ./configure: 23: ./configure: Syntax error: "(" unexpected Here is the relevant section of configure: # configure ...
8
votes
2answers
142 views

Variable assignments affect present running shell

While writing some code I found out that this line: $ TZ="America/Los_Angeles" date; echo "$TZ" Thu Dec 24 14:39:15 PST 2015 Correctly gives the actual time at "Los Angeles" and that the ...
0
votes
2answers
63 views

How can I use fdisk to create a ntfs partition on /dev/sdx?

I would like to know how to create a ntfs partition on /dev/sdx. I could not figure out if I should use partition type 7 86 or 87. What is the full list of commands to use?
1
vote
1answer
38 views

How can the read/write speed of a partition or drive be measured? [duplicate]

How can I preferable from the terminal measure the read and write speeds of /dev/sdx?
5
votes
8answers
400 views

Generate two sequences of numbers separated by “|”

I'm using bash (CentOS 5) and looking to generate this output (I assume I could use seq or echo together maybe?): 1|1, 2|2, 3|3, .... 31|31, 32|32, 33|33, I googled seq examples for over two hours ...
118
votes
15answers
48k views

Get exit status of process that's piped to another

I have two processes foo and bar, connected with a pipe: $ foo | bar bar always exits 0; I'm interested in the exit code of foo. Is there any way to get at it?
0
votes
1answer
23 views

Update phpmyadmin config.inc.php file in bash

When you download and extract latest phpMyAdmin, it comes with a config.sample.inc.php file. I would like to set a random blowfish_secret value on this line: $cfg['blowfish_secret'] = ''; /* YOU ...
48
votes
6answers
3k views

Is there any reason to have a shebang pointing at /bin/sh rather than /bin/bash?

In most shell scripts I've seen (besides ones I haven't written myself), I noticed that the shebang is set to #!/bin/sh. This doesn't really surprise me on older scripts, but it's there on fairly new ...
1
vote
0answers
27 views

'Chain' shells' profile and runcom files?

While setting zsh up, I found a post stating that to keep a .zshrc as clean and backwards compatible as possible, one can 'chain' the shells' configuration files. If I recall, it consists more or less ...
1
vote
3answers
61 views

Renaming thousand files with similar names

I'm having a difficulty creating a bash script to rename my files,so i'm asking for help. The files are in the same folder and all look something like this 1xxx_(bunch of characters)=(bunch of ...