Tag: shell

64 votes
20 answers
2.6K views
Running shell command and capturing the output

I want to write a function that will execute a shell command and return its output as a string, no matter, is

avatar
Rufus
0 1 0 9
asked 07 September, 2021
52 votes
21 answers
379 views
Why do people write #!/usr/bin/env python on the first line of a Python script?

It seems to me like the files run the same without that line.

avatar
Jesenia
0 1 0 9
asked 07 September, 2021
63 votes
20 answers
1.5K views
How to call shell commands from Ruby

How do I call shell commands from inside of a Ruby program? How do I then get output from these commands back

avatar
Benton
0 1 0 9
asked 07 September, 2021
53 votes
23 answers
1.4K views
How can I declare and use Boolean variables in a shell script?

I tried to declare a Boolean variable in a shell script using the following syntax: variable=$false variable

avatar
Freida
0 1 0 9
asked 07 September, 2021
62 votes
14 answers
1.7K views
YYYY-MM-DD format date in shell script

I tried using $(date) in my bash shell script, however, I want the date in YYYY-MM-DD format. How do I get thi

avatar
Adolfo
0 1 0 9
asked 07 September, 2021
61 votes
20 answers
1.1K views
How to use SSH to run a local shell script on a remote machine?

I have to run a local shell script (windows/Linux) on a remote machine. I have SSH configured on both machine

avatar
Dusty
0 1 0 9
asked 07 September, 2021
54 votes
30 answers
437 views
How to specify the private SSH-key to use when executing shell command on Git?

A rather unusual situation perhaps, but I want to specify a private SSH-key to use when executing a shell (git

avatar
Deedee
0 1 0 9
asked 07 September, 2021
58 votes
21 answers
909 views
How to convert a string to lower case in Bash?

Is there a way in bash to convert a string into a lower case string? For example, if I have: a="Hi all" I

avatar
Tuan
0 1 0 9
asked 07 September, 2021
66 votes
12 answers
2.5K views
Difference between sh and bash

When writing shell programs, we often use /bin/sh and /bin/bash. I usually use bash, but I don't know wha

avatar
Luis
0 1 0 9
asked 07 September, 2021
64 votes
11 answers
622 views
Check existence of input argument in a Bash shell script

I need to check the existence of an input argument. I have the following script if [ "$1" -gt "-1" ] then e

avatar
Virgil
0 1 0 9
asked 07 September, 2021
61 votes
30 answers
1.2K views
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

avatar
Kristopher
0 1 0 9
asked 07 September, 2021
59 votes
30 answers
2.5K views
How to exclude a directory in find . command

I'm trying to run a find command for all JavaScript files, but how do I exclude a specific directory? He

avatar
Nereida
0 1 0 9
asked 07 September, 2021
61 votes
20 answers
3.1K 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: f

avatar
Venice
0 1 0 9
asked 07 September, 2021
55 votes
30 answers
854 views
How can I count all the lines of code in a directory recursively?

We've got a PHP application and want to count all the lines of code under a specific directory and its su

avatar
Deedee
0 1 0 9
asked 07 September, 2021
58 votes
20 answers
1.7K views
How do I iterate over a range of numbers defined by variables in Bash?

How do I iterate over a range of numbers in Bash when the range is given by a variable? I know I can do this

avatar
Benton
0 1 0 9
asked 07 September, 2021
58 votes
16 answers
1K 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?

avatar
Freida
0 1 0 9
asked 07 September, 2021
58 votes
30 answers
2.5K 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

avatar
Basil
0 1 0 9
asked 07 September, 2021
59 votes
14 answers
1.1K 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 r

avatar
Elicia
0 1 0 9
asked 07 September, 2021
53 votes
19 answers
1.4K 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?

avatar
Fabian
0 1 0 9
asked 07 September, 2021
56 votes
18 answers
2.4K 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?

avatar
Robt
0 1 0 9
asked 07 September, 2021