Tag: sh

58 votes
21 answers
1.3K views
Get current directory name (without full path) in a Bash script

How would I get just the current working directory name in a bash script, or even better, just a terminal comm

avatar
Patsy
0 1 0 9
asked 07 September, 2021
53 votes
30 answers
2.5K views
Shell command to sum integers, one per line?

I am looking for a command that will accept (as input) multiple lines of text, each line containing a single i

avatar
Robt
0 1 0 9
asked 07 September, 2021
62 votes
11 answers
1.1K views
How do I put an already-running process under nohup?

I have a process that is already running for a long time and don't want to end it. How do I put it under

avatar
Wilfredo
0 1 0 9
asked 07 September, 2021
54 votes
12 answers
2.8K views
Should I put #! (shebang) in Python scripts, and what form should it take?

Should I put the shebang in my Python scripts? In what form? #!/usr/bin/env python or #!/usr/local/bin/py

avatar
Omar
0 1 0 9
asked 07 September, 2021
57 votes
10 answers
1.2K views
Replace one substring for another string in shell script

I have "I love Suzi and Marry" and I want to change "Suzi" to "Sara". #!/bin/bash firstString="I love Suzi an

avatar
Shantay
0 1 0 9
asked 07 September, 2021
61 votes
14 answers
303 views
How to echo shell commands as they are executed

In a shell script, how do I echo all shell commands called and expand any variable names? For example, given

avatar
Kisha
0 1 0 9
asked 07 September, 2021
48 votes
14 answers
2.3K views
Defining a variable with or without export

What is export for? What is the difference between: export name=value and name=value

avatar
Basil
0 1 0 9
asked 07 September, 2021
61 votes
14 answers
775 views
How to reload .bash_profile from the command line?

How can I reload .bash_profile from the command line? I can get the shell to recognize changes to .bas

avatar
Bryan
0 1 0 9
asked 07 September, 2021
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
377 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
433 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
907 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
619 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