Category "bash"

Suppressing summary information in `wc -l` output

I use the command wc -l count number of lines in my text files (also i want to sort everything through a pipe), like this: wc -l $directory-path/*.txt | sort -

How can I print a newline as \n in Bash?

Basically, I want to achieve something like the inverse of echo -e. I have a variable which stores a command output, but I want to print newlines as \n.

How to extract value from json contained in a variable using jq in bash

I am writing a bash script which has a json value stored in a variable now i want to extract the values in that json using Jq. The code used is. json_val={"co

Script file to run in android devices with help of the sh present in adb shell

I am facing a problem in writing a shell script for android devices to be run only on sh present in the device (/system/bin/sh). I have written the following s

-bash: /Users/myname/.bash_profile: Permission denied

I installed rvm (ruby version manager) and it was success, but I got WARNING: You have '~/.profile' file, you might want to load it, to do that add the fo

git clone and cd into it

If I wanted to make a directory and change directory into it all in one line, I could do something like this: mkdir dir_name && cd $_ How can I do the

'If' statements and one line Python scripts from the command line

Why do I receive a syntax error for the following one-liner Python code? python -c 'import re; if True: print "HELLO";' File "<string>", line 1 impo

How to recognize whether bash or dash is being used within a script?

I'm writing a bash script and it throws an error when using "sh" command in Ubuntu (it seems it's not compatible with dash, I'm learning on this subject). So I

Cannot import PyTorch in Alpine Docker Container

The MRE below should be enough to explain what I'm trying to do. Google doesn't help as it seems to be a unique error, which surprised me since Alpine & PyT

How do you compare the value of an array to a variable in bash script?

I'm practicing bash and honestly, it is pretty fun. However, I'm trying to write a program that compares an array's value to a variable and if they are the same

How do you compare the value of an array to a variable in bash script?

I'm practicing bash and honestly, it is pretty fun. However, I'm trying to write a program that compares an array's value to a variable and if they are the same

How to check if ssh-agent is already running in bash?

I have a sample sh script on my Linux environment, which basically run's the ssh-agent for the current shell, adds a key to it and runs two git commands: #!/bi

history -a vs -w in BASH. How to replace/append and ignore/erase duplicates?

I'm writing my PROMPT_COMMAND="history -a;$PROMPT_COMMAND" but I still get some duplicates from different terminal sessions. It seems I still will get some dupl

How to split strings over multiple lines in Bash?

How can i split my long string constant over multiple lines? I realize that you can do this: echo "continuation \ lines" >continuation lines However, if you

How to check the checksum through commandline?

I want to do something like this on commandline on my UNIX variant if (shasum httpd-2.4.7.tar.bz2 == 19asdasdasd56462e44d61a093ea57e964cf0af05c0e) echo 'good t

gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now

I have a Bash script that creates a .tar.gz file, encrypts, and then sends it to a drive. However, I cannot open the .tar.gz file afterwards. Here is my process

Rename multiple files, but only rename part of the filename in Bash

I know how I can rename files and such, but I'm having trouble with this. I only need to rename test-this in a for loop. test-this.ext test-this.volume001+02.

Mac Terminal Sending Email With Attachment

I'm trying to make a bash script that will send an email to all contacts which will contain a message and an attachment. This is not for malicious purposes. Ho

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 what's the difference between them. What's main difference

Running shell script in parallel

I have a shell script which shuffles a large text file (6 million rows and 6 columns) sorts the file based the first column outputs 1000 files So the pseu