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
291 views

How to execute a Bash comand and execute two statements on failure?

Ì want to execute a Bash command, followed by two actions if and only if the test returns an error. I would prefer to solve this task as a one-liner in Bash. Here are the two forms I have tried: ...
2
votes
4answers
7k views

How do I tell if a folder is actually a symlink and how do I fix it if it's broken?

How do I tell if I have a symlink, a shortcut of some sort, or a folder in Linux? Please see following screenshot. As you can see, the ls command lists objects where some are colored in dark blue ...
1
vote
4answers
6k views

How to send many commands to shell and wait for the command behind ends

Hello I have around 20 commands and I have to send all of this to Unix shell, and copy the result, but I don't know how to do it. I am not sure about what shell I have, because it is a small program ...
9
votes
4answers
6k views

How can I kill and wait for background processes to finish in a shell script when I Ctrl+C it?

I'm trying to set up a shell script so that it runs background processes, and when I Ctrlc the shell script, it kills the children, then exits. The best that I've managed to come up with is this. It ...
1
vote
1answer
2k views

Meaning of `export PATH=…` in .bash_profile

I'm using a mac for some years now and as I'm currently learning ruby on rails, I felt like I should learn more about the system I'm using. I took a look at the ~/.bash_profile, it looks like this ...
1
vote
1answer
310 views

how to send keyboard signal using a shell script

I have an application in graphical interface that when I run it, it's not opened in full screen mode, but when I use the keyboard shortcut Alt+Ctrl+M , it becomes fullscreen, I want to change the ...
1
vote
1answer
120 views

Unknown syntax in /etc/rc.d/init.d/functions

Looking at the file /etc/rc.d/init.d/functions, I can see the following is declaring a number of variables as local variables. However, why are the variables killlevel and pid_file have an equal sign ...
2
votes
1answer
240 views

kdialog --getsavefilename target/directory?

When I use kdialog --getsavefilename /path/to/specific/folder/, it opens folder/'s parent directory, not folder/ itself. How do I get it to start where I want it to?
0
votes
1answer
71 views

Getting tree command to not display directories

I've read through the man pages for tree but I don't know if it is possible to have tree list only the filenames for all files that appear in any recursive search of a directory. The closest I have ...
6
votes
4answers
5k 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 ...
4
votes
1answer
113 views

How can I configure ZSH's vi mode to persist the state between commands?

I am aware how to set ZSH's default line editor to use vi-like keybindings... bindkeys -v ...and even to default each new prompt to be in command mode instead of insert mod by default... ...
4
votes
4answers
5k views

Can IFS (Internal Field Separator) function as a single seperator for multiple consecutive delim chars?

Parsing an array using IFS with non-whites space values creates empty elements. Even using tr -s to shrink multiple delims to a single delim isn't enough. An example may explain the issue more ...
1
vote
2answers
98 views

Environment variable for command called via nice

I need to set an environment variable for a command that is being called via nice. [Bash and dash, Slackware and FreeBSD.] $ JIM=20 nice -n 10 echo $JIM $ Nope, echo can't see JIM $ nice -n ...
33
votes
5answers
3k views

What are the fundamental differences between the mainstream *NIX shells?

What are the fundamental differences between the mainstream *NIX shells and what scenarios might prompt you to use one over the other? I understand that some of it probably comes down to user ...
0
votes
4answers
572 views

Why does the command shuf file > file leave an empty file?

I know this is sort of a duplicate of another question (Why this sort command gives me an empty file?) but I wanted to expand on the question in response to the answers given. The command shuf ...
6
votes
1answer
366 views

Bash is automatically reloading (injecting) updates into a running script upon saving it: Why? Any practical use?

I was writing a bash script, and happened to updated the code (saved the script file to disk) while the script was waiting for some input in a while loop. After I returned to the terminal and ...
4
votes
3answers
21k views

How can I delete all files with a particular extension in a particular folder?

If I set the current/working directory (navigating to it using cd) to some particular directory and then type: rm *.xvg What will this command do? Is it true that the above command will only delete ...
7
votes
5answers
7k views

In linux, how to delete all files EXCEPT the pattern *.txt?

I know how to delete all txt file under current directory by rm *.txt. Does anyone know how to delete all files in current directory EXCEPT txt file?
3
votes
1answer
91 views

How can the order of execution in the shell as it relates to redirection be upset about 1 time out of a 1000 on my system? [duplicate]

Considering this Q&A about the order of execution in the shell as it relates to redirection, and despite the fact that if a file doesn't exist it gets created first so that cat example.txt | shuf ...
2
votes
1answer
149 views

xargs and < and > to the same files

I want to run git stripspace on all my source code files, on each build (or precommit or just manually), to remove extraneous whitespace, and later maybe to format the code in a standard way, So ...
2
votes
3answers
1k views

How can I create multiple files in the current directory in bash?

Is there a command to create multiple files in the current directory? i.e. if I would like to create __init__.py, views.py, models.py and admin.py as follows: > COMMAND __init__.py views.py ...
1
vote
1answer
714 views

Regular expression how to get value in shell script?

I have to write a shell script to get value from a string, something like: string="abcdef" pathName How can I use grep command with the use of regular expression to get "pathName"?
8
votes
5answers
2k views

`highlight` command

Is there a command which can be used to easily highlight (with colors, bold text or inverted back-/foreground) specific strings in stdin while passing the entire string to stdout? I'm thinking of ...
0
votes
1answer
41 views

Error in Dansguardian init.d sh script?

In the Dansguardian init.d script there is a function involved in shutdown that looks like: #!/bin/sh wait_for_pid() { local PID=$1 local RET=0 if [ $PID -eq 0 ] ; then return $RET fi # give ...
5
votes
2answers
6k views

Why does Ctrl-D (EOF) exit the shell?

Are you literally "ending a file" by inputting this escape sequence, i.e. is the interactive shell session is seen as a real file stream by the shell, like any other file stream? If so, which file? ...
2
votes
2answers
85 views

`cd` all screens to the PWD of the current screen

Suppose that I am running screen on a remote server with four open screens. Is there a quick way to cd all the screens to the working directory of the currently-open screen?
75
votes
4answers
1k views

Can I somehow add a “&& prog2” to an already running prog1?

Most shells provide functions like && and ; to chain the execution of commands in certain ways. But what if a command is already running, can I still somehow add another command to be executed ...
2
votes
3answers
643 views

bash adds extra single quotes

I have a problem executing my script. When executing it in debug mode (bash -x), I can see that bash is adding extra quotes. Therefor my script is failing. Here this is within my script: ...
2
votes
1answer
87 views

How does one determine the amount of space allocated to their command line?

How would one go about determining the amount of space allocated to their system for command lines. Is there anything else I need to be concerned with?
3
votes
2answers
173 views

How do you preserve a space in a literal expression in an array value in bash and how to trim down results from a sort command?

In the context of searching for expressions in log files, I was wondering generally if there was a way to quantify and qualify the contents of the logs in /var/log in some way. In particular, does the ...
4
votes
3answers
804 views

Help Shell script to pass variables to rsync

I'm trying to create a simple wrapper shell script for rsync. When I send file names to my script, rsync can never seem to identify the correct location. The file names have spaces in them. I've tried ...
2
votes
2answers
199 views

Nature of the positional parameters

I am beginner to shell scripting and wrote this script which sort of confused me a bit... function func { the variables received are echo $0: $1 and $2 } echo in the main script func ball boy The ...
4
votes
2answers
106 views

Why sed prints first string from file even if it's failed to find matching groups

I'm trying to write sed expression which will extract matching groups from file. E.g. I have .cue sheet and I want to extract it's genre tag. It has following format: $ cat file.cue | grep GENRE REM ...
5
votes
3answers
294 views

Can you pipe to a .bash_profile function?

I received a great function for highlighting files in Apple's finder using the command-line. It's basically a wrapper for osascript. I got it from Mac OS X: How to change the color label of files ...
2
votes
2answers
79 views

Process each line from text file and delete related files from disk

I used the find command to find several files and folders and output them to a text file like so: nohup find /oradba -name '*soapr*' 2>/dev/null >find_soapr_db40.txt & So instead of ...
1
vote
1answer
269 views

Alias for redirecting both standard output and standard error, as well as sending to background [duplicate]

I am trying to create an alias for redirecting both standard output and standard error of gedit to /dev/null, whilst sending the command to background. This works: $ alias gedit='gedit $1 > ...
9
votes
3answers
2k views

identify files with non-ASCII or non-printable characters in file name

In a directory size 80GB with approx 700,000 files, there are some file names with non-English characters in the file name. Other than trawling through the file list laboriously is there: An easy ...
47
votes
4answers
19k views

Difference between Login Shell and Non-Login Shell?

I understand the basic difference between an interactive shell and a non-interactive shell. But what exactly differentiates a login shell from a non-login shell? Can you give examples for uses of a ...
0
votes
1answer
182 views

Passing multiple scripts to shell over ssh

I have a somewhat lengthy script which sources other scripts to include the functions there. I'd like to execute this script remotely via ssh. Now I thought to make one script file of it (without ...
8
votes
1answer
133 views

Filter the clipboard content without using an intermediate file

I'm trying to modify the text that is in my clipboard, remove certain lines of that contains some strings and then get the output for further manipulation (I prefer coping to my clipboard only if I ...
20
votes
4answers
2k views

Automatically detect when I typed “vi” but meant “cd”?

Title says it all. About 5 times a day, I type "vi" when I meant "cd", and end up opening a directory in vi. It's making me NUTS. It seems like there should be a way to detect when I type in "vi + ...
1
vote
2answers
444 views

Escaping blackslash in sed

I am trying to write a sed command to replace a line in a file. The sed replace required the current working directory, which starts making the command a bit messy because of the characters that need ...
10
votes
1answer
6k views

touch: cannot touch `foo': No such file or directory

What could cause touch to fail with this error message? touch: cannot touch `foo': No such file or directory Note that an error due to incorrect permissions looks different: touch: cannot touch ...
7
votes
1answer
114 views

Do spellcheckers exist that are aware of Markdown?

I would like to run a spellchecker over my articles before I publish them. I think aspell is ok, but it should not try to check code blocks: asdfasdfa adsfa sdfa text to check adsfasd f ``` a wild ...
2
votes
2answers
302 views

Shell script to wait for a packet from a certain port

I want to start my minecraft server when someone tries to connect to it on port 25565. I have a plugin for the server which shuts it down after x amount of minutes without players online. With a shell ...
4
votes
4answers
168 views

How to deal with spaces in a variable

I'm working on some scripting: for x in `find ./ -name *.pdf` do echo pathname $x done My filenames are Test1 ( Volume II), Test2 ( Volume II). I'm getting a return of pathname Test1 pathname ( ...
7
votes
3answers
7k views

How do I change folder timestamps recursively to the newest file?

I was wondering if anyone knows how to change the timestamps of folders recursively based on the latest timestamp found of the files in that folder. So for example: ...
3
votes
2answers
721 views

grep string from contents of file command then delete file

I have a peculiar problem I need help with. I have a large batch of .docx files where a certain number of them are junk. I know how to identify these files from the file command, as they contain the ...
0
votes
1answer
359 views

How to escape spaces while using command's output in command line [duplicate]

I want to perform the following command in command line : $ md5sum $(find . -type f) But this would cause problems when it encounter files with spaces in filenames : md5sum: Kaufmann: No such ...
3
votes
2answers
15k views

Can I redirect output to a log file and background a process at the same time?

Can I redirect output to a log file and background a process at the same time? In other words, can I do something like this? nohup java -jar myProgram.jar 2>$1 > output.log & Or, is that ...