37 Answered Questions for the topic shell

Shell Linux Unix Bash

05/04/19

Aborting a shell script if any command returns a non-zero value?

I have a Bash shell script that invokes a number of commands. I would like to have the shell script automatically exit with a return value of 1 if any of the commands return a non-zero value. Is... more
Shell Unix

05/03/19

Unix shell script find out which directory the script file resides?

Basically I need to run the script with paths related to the shell script file location, how can I change the current directory to the same directory as where the script file resides?
Shell Unix Bash Awk

05/03/19

Bash tool to get nth line from a file?

Is there a "canonical" way of doing that? I've been using `head -n | tail -1` which does the trick, but I've been wondering if there's a Bash tool that specifically extracts a line (or a range of... more
Shell Linux Bash Grep

05/02/19

How to 'grep' a continuous stream?

Is that possible to use `grep` on a continuous stream? What I mean is sort of a `tail -f <file>` command, but with `grep` on the output in order to keep only the lines that interest... more

05/01/19

How can I copy the output of a command directly into my clipboard?

How can I pipe the output of a command into my clipboard and paste it back when using a terminal? For instance: cat file | clipboard
Shell Unix Find

04/27/19

find without recursion?

Is it possible to use the `find` command in some way that it will not recurse into the sub-directories? For example, DirsRoot |-->SubDir1 | |-OtherFile1 |-->SubDir2 | |-OtherFile2 ... more
Shell Python Shebang

04/20/19

Why do people write the #!/usr/bin/env python shebang on the first line of a Python script?

It seems to me like the files run the same without that line.
Shell Linux Unix Bash

03/26/19

Linux: copy and create destination dir if it does not exist?

I want a command (or probably an option to cp) that creates the destination directory if it does not exist. Example: cp -? file /path/to/copy/file/to/is/very/deep/there
Shell Unix Bash Tcsh

03/18/19

How to determine the current shell I'm working on?

How can I determine the current shell I am working on? Would the output of the `ps` command alone be sufficient? How can this be done in different flavors of UNIX?

03/14/19

How to join multiple lines of file names into one with custom delimiter?

I would like to join the result of `ls -1` into one line and delimit it with whatever i want. Are there any standard Linux commands I can use to achieve this?
Shell Linux Unix Bash

03/14/19

How to run a shell script on a Unix console or Mac terminal?

I know it, forget it and relearn it again. Time to write it down.
Shell Unix

03/14/19

Listing only directories in UNIX?

I want to list only the directories in specified path (`ls` doesn't have such option). Also, can this be done with a single line command?

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.