Category "bash"

What are the differences between a login shell and interactive shell?

What is a login shell and interactive shell, and what is a .bash_profile and .bashrc?

How to check if a user disconnected, if it's a new disconnection and the server on which the action was made?

I have to create a shell program, such that each time certain users (given as parameters) connect/disconnect from the system, it will save in a text file if its

How to get a random string of 32 hexadecimal digits through command line?

I'd like to put together a command that will print out a string of 32 hexadecimal digits. I've got a Python script that works: python -c 'import random ; print

How to Fix Permissions on Home-brew on MacOS High Sierra

When I tried to install python onto homebrew it downloaded it and then an error message popped up at the end that stopped it from completing. When I try to do i

How to capture output of df -h --total - Bash

I am writing a script which will be used to gather information on the available and used space on different partitions across servers. I need to be able to capt

-bash: __git_ps1: command not found

I tried to install Ruby 2.0. My command line urped and now looks like the following: -bash: __git_ps1: command not found [11:58:28][whatever@whatever ~]$ I

How do I get a variable into a $(shell) command in a makefile?

❯ make --version GNU Make 3.81 ❯ bash --version GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18) How can I pass a variable from inside

How do I escape a series of backslashes in a bash printf?

The following script yielded an unexpected output: printf "escaped slash: \\ \n" printf "2 escaped slashes: \\\\ \n" printf "3 escaped slashes: \\\\\\ \n" prin

Concatenating variables in Bash [duplicate]

I am trying to add a variable to the middle of a variable, so for instance in PHP I would do this: $mystring = $arg1 . '12' . $arg2 . 'endoffi

Copy current command at bash prompt to clipboard

I would like a quick keyboard command sequence to copy the current command at a bash prompt to the clipboard. So that, for example, to copy the last bash comm

How to detect array start index by current shells (zsh/bash)?

We all know arrays in Bash are indexed from zero, and in zsh are indexed from one. How can the script know it should use 0 or 1 if I can't ensure the running en

How to detect array start index by current shells (zsh/bash)?

We all know arrays in Bash are indexed from zero, and in zsh are indexed from one. How can the script know it should use 0 or 1 if I can't ensure the running en

Windows PATH to posix path conversion in bash

How can I convert a Windows dir path (say c:/libs/Qt-static) to the correct POSIX dir path (/c/libs/Qt-static) by means of standard msys features? And vice vers

How to use sed to remove the last n lines of a file

I want to remove some n lines from the end of a file. Can this be done using sed? For example, to remove lines from 2 to 4, I can use $ sed '2,4d' file But

How to use sed/grep to extract text between two words?

I am trying to output a string that contains everything between two words of a string: input: "Here is a String" output: "is a" Using: sed -n '/Here/,/

How to export an associative array (hash) in bash?

Related, but not a duplicate of: How to define hash tables in Bash? I can define and use a bash hash, but I am unable to export it, even with the -x flag. For

How not to pass the locale through an ssh connection command

I have some aliases for ssh, example: alias buildWork="ssh work '~/build_app'" The problem is that the ssh command passes some variables like $LC_CTYPE that ca

How to prevent docker container from stopping after executing sh script file

im running a docker container as shown below, after the sh files are executed the container terminate by default, how i can keep the container working in backgr

I just assigned a variable, but echo $variable shows something else

Here are a series of cases where echo $var can show a different value than what was just assigned. This happens regardless of whether the assigned value was "do

How to extract last part of string in bash?

I have this variable: A="Some variable has value abc.123" I need to extract this value i.e abc.123. Is this possible in bash?