Category "bash"

How to format a bash array as a JSON array

I have a bash array X=("hello world" "goodnight moon") That I want to turn into a json array ["hello world", "goodnight moon"] Is there a good way for me

Limit the number of running jobs in SLURM

I am queuing multiple jobs in SLURM. Can I limit the number of parallel running jobs in slurm? Thanks in advance!

How to check if a file is empty in Bash?

I have a file called diff.txt. I Want to check whether it is empty. I wrote a bash script something like below, but I couldn't get it work. if [ -s diff.txt ] t

Duplicate IO with file descriptors

I would like to route a file descriptor to multiple places at the same time. For instance I would like every command in my script to print stdout to /dev/ps/9

Recursive copy of a specific file type maintaining the file structure in Unix/Linux? [closed]

I need to copy all *.jar files from a directory maintaining the folder structure of the parent directories. How can I do it in UNIX/Linux term

SSH and identity file for jump server

I'm trying to log into my-server through a jump server, jump.example.com. I can successfully log into the jump server without a password request: ssh -i .ssh/id

Python print output not appearing when called from bash

Here is a minimal working example: I have a python script test.py that contains: print("Hello") and I have a bash script test.sh that calls that python functio

How to know the process id of current bash session? [duplicate]

I'm on a linux server and admin user. There're many admin users using this machine at the same time. So under current bash command line, how t

How can I convert a series of images to a PDF from the command line on linux? [closed]

I have a scanning server I wrote in cgi/bash and want to be able to convert a bunch of images (all in one folder) to a pdf from the command li

Authentication failed on tfs server

I am having a really weird issue with git bash on windows. When I am working in Visual Studio I have no problem working with my git repo stored in a tfs server

How to pass environment variables from a string to a bash command

I have a variable AAA which is in this format AAA='BBB=1 CCC=2 DDD=3' How can I use this to set environment variables BBB, CCC and DDD in a command I run (wi

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