43 Answered Questions for the topic Bash

05/09/19

How to change the output color of echo in Linux?

I am trying to print a text in the terminal using echo command. I want to print the text in a red color. How can I do that?

05/06/19

How do I prompt for Yes/No/Cancel input in a Linux shell script?

I want to pause input in a shell script, and prompt the user for choices. The standard 'Yes, No, or Cancel' type question. How do I accomplish this in a typical bash prompt?
Bash Linux Unix

05/05/19

How do I write stderr to a file while using "tee" with a pipe?

I know how to use `tee` to write the output (`STDOUT`) of `aaa.sh` to `bbb.out`, while still displaying it in the terminal: ./aaa.sh | tee bbb.out How would I now also write `STDERR` to a file... more

05/05/19

How to make the 'cut' command treat same sequental delimiters as one?

I'm trying to extract a certain (the fourth) field from the column-based, 'space'-adjusted text stream. I'm trying to use the `cut` command in the following manner: `cat text.txt | cut -d " " -f... more
Bash Linux Posix

05/04/19

How to kill all processes with a given partial name?

I want to kill all processes that I get by: ps aux | grep my_pattern How to do it? This does not work: pkill my_pattern

05/04/19

How do I know the script file name in a Bash script?

How can I determine the name of the Bash script file inside the script itself? Like if my script is in file `runme.sh`, then how would I make it to display "You are running runme.sh" message... more

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
Bash Unix Shell 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
Bash Unix Cut

05/03/19

use space as a delimiter with cut command?

I want to use space as a delimiter with the `cut` command. What syntax can I use for this?

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

04/25/19

Recursively look for files with a specific extension?

I'm trying to find all files with a specific extension in a directory and its subdirectories with my bash (Latest Ubuntu LTS Release). This is what's written in a script file: #!/bin/bash ... more

04/25/19

How does "cat << EOF" work in bash?

I needed to write a script to enter multi-line input to a program (`psql`). After a bit of googling, I found the following syntax works: cat << EOF | psql ---params BEGIN; `pg_dump... more

04/04/19

How do I syntax check a Bash script without running it?

Is it possible to check a bash script syntax without executing it? Using Perl, I can run `perl -c 'script name'`. Is there any equivalent command for bash scripts?
Bash Linux Unix Path

03/27/19

How to permanently set $PATH on Linux/Unix?

I'm trying to add a directory to my path so it will always be in my Linux path. I've tried: export PATH=$PATH:/path/to/dir This works, however each time I exit the terminal and start a new... more

03/26/19

How do I get cURL to not show the progress bar?

I'm trying to use cURL in a script and get it to ***not*** show the progress bar. I've tried the `-s`, `-silent`, `-S`, and `-quiet` options, but none of them work. Here's a typical command I've... more
Bash Unix Shell 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?

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.

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.