Passing arguments by reference

I want to ask if it is possible to pass arguments to a script function by reference: i.e. to do something that would look like this in C++: void boo(int &myint) { myint = 5; } int main() { ...

Find out if a command exists on POSIX system

I want to be able to tell if a command exists on any POSIX system from a shell script. On Linux, I can do the following: if which <command>; then ...snip... fi However, Solaris and MacOS...

In the shell, what does " 2>&1 " mean?

In a Unix shell, if I want to combine stderr and stdout into the stdout stream for further manipulation, I can append the following on the end of my command: 2>&1 So, if I want to use head on...

Run Python script without Windows console appearing

Is there any way to run a Python script in Windows XP without a command shell momentarily appearing? I often need to automate WordPerfect (for work) with Python, and even if my script has no...

How do I determine if a web page exists with shell scripting?

I am trying to make a program that can convert a series of manga scans into one pdf file, and I don't want to have to attempt to download the picture to determine if I have the right url. Is...

How can I parse a YAML file from a Linux shell script?

I wish to provide a structured configuration file which is as easy as possible for a non-technical user to edit (unfortunately it has to be a file) and so I wanted to use YAML. I can't find any...

How can I recursively find all files in current and subfolders based on wildcard matching?

How can I recursively find all files in current and subfolders based on wildcard matching?

Loop through an array of strings in Bash?

I want to write a script that loops through 15 strings (array possibly?) Is that possible? Something like: for databaseName in listOfNames then # Do something end

Shell script - remove first and last quote (") from a variable

Below is the snippet of a shell script from a larger script. It removes the quotes from the string that is held by a variable. I am doing it using sed, but is it efficient? If not, then what is...

Capture stdout and stderr into different variables

Is it possible to store or capture stdout and stderr in different variables, without using a temp file? Right now I do this to get stdout in out and stderr in err when running some_command, but...

Is there a way to 'pretty' print MongoDB shell output to a file?

Specifically, I want to print the results of a mongodb find() to a file. The JSON object is too large so I'm unable to view the entire object with the shell window size.

Bash while read loop extremely slow compared to cat, why?

A simple test script here: while read LINE; do LINECOUNT=$(($LINECOUNT+1)) if [[ $(($LINECOUNT % 1000)) -eq 0 ]]; then echo $LINECOUNT; fi done When I do cat my450klinefile.txt |...

Transpose one line/lines from column to row using shell

I want convert a column of data in a txt file to a row of a csv file using unix commands. example: ApplChk1, ApplChk2, v_baseLoanAmountTI, v_plannedClosingDateField, downPaymentTI, this is a...

How to execute script in the current shell on Linux?

Is there a way to mark a script to be executed in the current shell from whitin It? I know I can use: . ./path/myscript.sh but I need a way to include the "dot" way inside the script. Edit: Here...

Return Java system exit value to bash script

I am trying to get the return value from a java program ( System.exit(1);) into a shell script, but it seems like its returning the jvm exit code, which is always 0, if it doesnt crash. For...

Trim trailing and leading slash in bash - joining param substitutions?

I'm trying to trim a possible / from the start and end of a string in bash. I can accomplish this via the following: string="/this is my string/" string=${string%/} string=${string#/} echo $string...

Remove older backup from directory using shell command

In my shell script, I am creating a backup of my folder. I am setting this activity by cronjob and the schedule keeps on changing. It is keeping the backup with timestamp. Like for e.g : cd...

How to keep a folder up-to-date with a git repo?

This is for a shell script that will periodically check github for the latest code, and download, compile, and run it if there is any difference between what I already have locally and what was...

Create HTML table using AWK/SED command on unix

I have a file that looks like this. Is there any way I could format the file to how I want it to look like ? ( see below ) I used various verisons of sed/awk but it seems to not work. The purpose...

How to create directory if doesn't exists in sftp

I want to create a directory if it doesn't exists after login to sftp server. test.sh sftp [email protected] << EOF mkdir test put test.xml bye EOF Now i call test.sh and upload different files...

assign number value to alphabet in shell/bash

I have a script that prompts for the user to enter a 3 letter code. I need to convert that code to a number that corresponds to a=01, b=02....etc for the first two letters of that code. For...

Capture exit status from function in shell script

I have a very simple script. test.sh _EXECUTE_METHOD () { exit 1 } _EXECUTE_METHOD ERROR_CODE=$? if [[ $ERROR_CODE -eq 1 ]]; then echo "Got error" exit 0 fi This script terminate...

Bash -- find a list of files with more than 3 lines

I have a directory of files and I want to find a list of files who has more than 2 lines. I know I can use wc -l to test each file, but how do I wrap it up in bash? Sorry for the newbie question,...

Why does my Morse code converter display no output?

I want to make a morse code converter that converts letters from a txt file to morse code and morse code from a txt file to letters. The way of execution is ./morse.sh -e Text.txt for encoding and...

can't debug bash scripts using VSCode

I've installed VSCode with Bash debug extension. Before that, I've installed bashdb and I've verified its version using (bashdb --version) and it's 4.4. Now, the extension creates an empty file...

Read csv and Print matched text using Jenkins declarative Pipeline Script

currently Im working on jenkins declarative pipeline scripting it would be great if I can get some help with the scripting below. I have 10 CSV files in a location. I want to open each file and...

Check docker-compose services are running or not

I am writing a script which will check docker service but I want check services which are inside the docker-compose without getting into it. For ex: we have custom services like tass and inception...

GitLab CI collapsible regions are behaving weird

I'm trying to ouptut custom collapsible regions on Gitlab CI, using the recommendation as per the GitLab CI docs, however this isn't working as expected. I'm running the docker:20.10.7 image which...

Python upgrades results in "AttributeError: module 'collections' has no attribute 'MutableMapping'" error when starting shell

I just upgraded to Python 3.10 on Mac OS X Big Sur. When I fire up the shell now, I get an error $ python manage.py shell ... Traceback (most recent call last): File...

Count trailing newlines with POSIX utilities or Perl

I'm looking for ways to count the number of trailing newlines from possibly binary data either: read from standard input or already in a shell variable (then of course the "binary" excludes at...