Top "Bash" questions

For questions about scripts written for the Bash command shell.

Can a shell script set environment variables of the calling shell?

I'm trying to write a shell script that, when run, will set some environment variables that will stay set in …

bash shell csh tcsh
How to make "if not true condition"?

I would like to have the echo command executed when cat /etc/passwd | grep "sysa" is not true. What am …

bash if-statement syntax boolean-expression
Extract file basename without path and extension in bash

Given file names like these: /the/path/foo.txt bar.txt I hope to get: foo bar Why this doesn't …

linux bash unix filenames
An example of how to use getopts in bash

I want to call myscript file in this way: $ ./myscript -s 45 -p any_string or $ ./myscript -h #should display help $ ./…

bash shell getopts
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 …

bash unix shell csh tcsh
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 …

linux bash recursion
How can I exclude all "permission denied" messages from "find"?

I need to hide all permission denied messages from: find . > files_and_folders I am experimenting when such message …

bash error-handling find file-permissions
How to split a large text file into smaller files with equal number of lines?

I've got a large (by number of lines) plain text file that I'd like to split into smaller files, also …

bash file unix
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 …

bash shell unix awk sed
How to have the cp command create any necessary folders for copying a file to a destination

When copying a file using cp to a folder that may or may not exist, how do I get cp …

linux bash cp