Skip to main content

Questions tagged [shell]

The term 'shell' refers to a general class of text-based interactive command interpreters most often associated with the Unix & Linux operating systems. For questions about shell scripting, please use a more specific tag such as 'bash', 'powershell' or 'ksh'. Without a specific tag, a portable (POSIX-compliant) solution should be assumed, though using 'posix' in addition or 'sh' instead is preferable.

6173 votes
66 answers
4.8m views

How do I execute a program or call a system command?

How do I call an external command within Python as if I had typed it in a shell or command prompt?
freshWoWer's user avatar
  • 63.5k
4469 votes
35 answers
3.3m views

How do I check if a directory exists or not in a Bash shell script?

What command checks if a directory exists or not within a Bash shell script?
Grundlefleck's user avatar
3563 votes
30 answers
3.2m views

How to check if a string contains a substring in Bash

I have a string in Bash: string="My string" How can I test if it contains another string? if [ $string ?? 'foo' ]; then echo "It's there!" fi Where ?? is my unknown operator. ...
davidsheldon's user avatar
  • 39.5k
3553 votes
31 answers
5.1m views

How to concatenate string variables in Bash

In PHP, strings are concatenated together as follows: $foo = "Hello"; $foo .= " World"; Here, $foo becomes "Hello World". How is this accomplished in Bash?
Strawberry's user avatar
  • 67.3k
3484 votes
17 answers
3.5m views

How do I copy a folder or file from remote to local using scp?

How do I copy a folder or file from remote to local host using scp? I use ssh to log in to my server. Then, I would like to copy the remote folder foo to local /home/user/Desktop. How do I achieve ...
Slasengger's user avatar
  • 35.1k
3183 votes
19 answers
1.8m views

What does " 2>&1 " mean?

To combine stderr and stdout into the stdout stream, we append this to a command: 2>&1 e.g. to see the first few errors from compiling g++ main.cpp: g++ main.cpp 2>&1 | head What does ...
Tristan Havelick's user avatar
3031 votes
19 answers
4.6m views

How can I recursively find all files in current and subfolders based on wildcard matching?

How can I recursively find all files in current and subfolders based on wildcard matching?
john's user avatar
  • 34.8k
2946 votes
39 answers
3.6m views

How do I split a string on a delimiter in Bash?

I have this string stored in a variable: IN="[email protected];[email protected]" Now I would like to split the strings by ; delimiter so that I have: ADDR1="[email protected]" ADDR2="[email protected]" I don't ...
stefanB's user avatar
  • 79k
2928 votes
17 answers
2.1m views

How to mkdir only if a directory does not already exist?

I am writing a shell script to run under the KornShell (ksh) on AIX. I would like to use the mkdir command to create a directory. But the directory may already exist, in which case I do not want to do ...
Spike Williams's user avatar
2440 votes
38 answers
2.3m views

How to check if a variable is set in Bash

How do I know if a variable is set in Bash? For example, how do I check if the user gave the first parameter to a function? function a { # if $1 is set ? }
prosseek's user avatar
  • 188k
2435 votes
16 answers
2.9m views

How do I set a variable to the output of a command in Bash?

I have a pretty simple script that is something like the following: #!/bin/bash VAR1="$1" MOREF='sudo run command against $VAR1 | grep name | cut -c7-' echo $MOREF When I run this script from the ...
John's user avatar
  • 24.8k
2354 votes
21 answers
2.5m views

How to delete from a text file, all lines that contain a specific string?

How would I use sed to delete all lines in a text file that contain a specific string?
A Clockwork Orange's user avatar
2304 votes
21 answers
2.1m views

Loop through an array of strings in Bash?

I want to write a script that loops through 15 strings (array possibly?) Is that possible? Something like: for databaseName in listOfNames then # Do something end
Mo.'s user avatar
  • 41.7k
2219 votes
49 answers
1.8m views

How do I exclude a directory when using `find`?

How do I exclude a specific directory when searching for *.js files using find? find . -name '*.js'
helion3's user avatar
  • 36.6k
2218 votes
18 answers
1.7m views

How to reload .bashrc settings without logging out and back in again?

If I make changes to .bashrc, how do I reload it without logging out and back in?
Jed Daniels's user avatar
  • 25.2k

15 30 50 per page
1
2 3 4 5
6192