bash

how to write function with nested commands

how to write function with nested commands I’m trying to write a find and cd function like so: findcd () { cd "$(dirname "$(find ‘$1’ -type ‘$2’ -name ‘$3′)")" } to be called like so: find . f [FILE_NAME] But it’s seeing the dollar sign and expecting more arguments as oppose to executing what’s inside. …

Total answers: 1

Unable to pass AWS CLI commands in double quotes in json syntax

Unable to pass AWS CLI commands in double quotes in json syntax I’m working with the below script,getting syntax error as unable to fetch credentials from secrets manager. "username":"AWS CLI command of access Key i have entered", "password":"AWS CLI command of secret key i have entered". Great if anyone can help #!/bin/bash # Send the …

Total answers: 2

How (abc) is parsed in bash

How (abc) is parsed in bash I’m using a program designed for windows that I compiled myself for GNU/linux. The program works in the command line, and one argument looks like this: prgm -arg1 abcd(10)(22) -i files.ext Where (10) and (22) are flags like a, b, c and d. This command is failing because bash …

Total answers: 2

renaming files based on matched pattern in another file

renaming files based on matched pattern in another file I have a list of files: out_CCGCGGTT+CTAGCGCT_R1.fq.gz out_TTATAACC+TCGATATC_R2.fq.gz out_GGACTTGG+CGTCTGCG_R1.fq.gz out_AAGTCCAA+TACTCATA_R2.fq.gz … the adaptor IDs (between the two underscores, like AACGTTCC+AGTACTCC, AACGTTCC+AGTACTCC) match with the first column of ID.file.txt head ID.file.txt: CCGCGGTT+CTAGCGCT NHL_332_N TTATAACC+TCGATATC NHL_333_T GGACTTGG+CGTCTGCG NHL_334_T AAGTCCAA+TACTCATA NHL_335_T ATCCACTG+ACGCACCT NHL_336_N GCTTGTCA+GTATGTTC NHL_337_N CAAGCTAG+CGCTATGT NHL_338_N TGGATCGA+TATCGCAC NHL_339_T …

Total answers: 2

How to reuse matched value in bash globbing?

How to reuse matched value in bash globbing? I was wondering whether it is possible to reuse whatever was matched in a path with globbing? (Just as it can usually be done with regex substitutions?) I’m aware that there are other solutions for the following example, but I’m just using it as an example for …

Total answers: 1

Bash script variable syntax: with some commands it works, with others it does not

Bash script variable syntax: with some commands it works, with others it does not I do not understand the behaviour of this variable: SSH_CONFIG_FILE="~/.ssh/config" echo $SSH_CONFIG_FILE ls -l $SSH_CONFIG_FILE ls -l ~/.ssh/config This is the output: ~/.ssh/config ls: cannot access ‘~/.ssh/config’: No such file or directory -rw——- 1 pm domain^users 1229 Sep 19 10:52 /home/pm/.ssh/config …

Total answers: 1

Can I extract complete dates from file with grep command?

Can I extract complete dates from file with grep command? I need help using grep to extract a zoned date time from a file on a Linux system. Source file is a XML with the data below: <item start="20231010073000 +0100" stop="20231010100000 +0100">…</item> And I need to extract the complete start date, but with grep I …

Total answers: 4

How to modify a gzipped file with sed and then zip again the file?

How to modify a gzipped file with sed and then zip again the file? I have a .vcf.gz file, with the following aspect: #CHROM POS ID REF ALT chr1 10894 chr1:10894:G:A G A chr1 10915 chr1:10915:G:A G A chr1 10930 chr1:10930:G:A G A I want to modify the CHROM column to remove ‘chr’ and to …

Total answers: 2

Test if all three filetypes are present in a directory

Test if all three filetypes are present in a directory I want to detect that there is one of each of the following filetypes in a directory .png , .txt, and .tar.gz. The following works correctly when testing for two of them shopt -s nullglob MYDIR=/some_dir if [ $MYDIR/*.png] && [ $MYDIR/*.txt]; then echo "All …

Total answers: 2

How to list process with their depth?

How to list process with their depth? I have a slightly different process tree question. I need to list the process and their depth in scalar value. pstree gives the result in a "graphic" manner. root 100930 0.0 0.3 839396 49020 ? Ssl Aug15 38:20 /usr/sbin/rsyslogd -n root 847414 0.0 0.0 76640 7788 ? Ss …

Total answers: 1

Copy file from Server A to Server B

Copy file from Server A to Server B I have requirement to copy files from Server A to Server B And then move the copied files Server A to Archive folder I have written the script, but it takes the directory name differently. Copying file from Server A to Server B is working, but moving …

Total answers: 2

sed: update 2 similar variables in a file but keep the upper and lowercase

sed: update 2 similar variables in a file but keep the upper and lowercase I have 2 variables in a file like below that I need to assign a new value inserted by one user input: read -p "Enter CName Name : " CName sid=C02SBX SID=C02SBX When I run the following GNU sed statement: sed …

Total answers: 2

Loop through file extension Annotate add EXIF Rename and Copy

Loop through file extension Annotate add EXIF Rename and Copy This script, reads user input from an entry like filename.jpg it creates a directory inside the current directory. Then renames the file and adds the files EXIF data it then copies the original file to the directory that was just created. Using convert from imagemagick …

Total answers: 1

How can I make this script run in the background?

How can I make this script run in the background? #!/bin/bash # Get the battery percentage for battery 0 battery0_percent=$(cat /sys/class/power_supply/BAT0/capacity) # Get the battery percentage for battery 1 battery1_percent=$(cat /sys/class/power_supply/BAT1/capacity) # Threshold level threshold=10 # Check if either battery is less than 10% if [ "$battery0_percent" -lt "$threshold" ] || [ "$battery1_percent" -lt "$threshold" …

Total answers: 4

Run `git commit -m` with single quotes in zsh

Run `git commit -m` with single quotes in zsh I sometimes use characters such as ! and $ in commit messages, they need to be manually escaped, but not if you use single quotes like this git commit -m ‘My $message here!’. I tried to write a function to make gc and all text following …

Total answers: 1

How to define a multiple page ranges for pdftk with a bash variable

How to define a multiple page ranges for pdftk with a bash variable I’m using Arch linux, Openbox window manager, and bash. Everything is up to date with the latest versions. Can anyone tell me why I can’t get the "$page_range" variable to show up within pdftk when I specify a couple of page ranges …

Total answers: 2

Rename and add a number to all folders in a directory

Rename and add a number to all folders in a directory I have a simulation folder on hpc which contains time directories from 0 to 50 with a step of 0.1 (so 501 folders in total with their names as 0, 0.1, 0.2.. and so forth). Example output of ls: 0 0.1 0.2 0.3 0.4 …

Total answers: 1