Click here to Skip to main content
15,891,136 members
Everything / Programming Languages / Bash

Bash

Bash

Great Reads

by Chris Maunder
A quick overview and a simple bash script to make your script output a little more lively
by Ahmed Khateeb
In this article, I will describe how to Create WordPress Bitnami VM, how to connect to VM, how to add Custom Domain to that VM and important steps to follow after fresh installation.
by Dave Kerr
Text in the command line can quickly get unwieldy. Here are some simple tricks you can use to navigate in the command line.

Latest Articles

by V. Subhash
Compile FFmpeg v7.0 CLI from source and check out some of its new features
by V. Subhash
A simple fix for excessively bright video and low-volume audio
by ToughDev
This post shows a way to change the default crontab editor in bash shell for Raspberry Pi.
by V. Subhash
How to get compile the latest FFmpeg source code and try out some new features

All Articles

Sort by Title

Bash 

1 Nov 2021 by wifinut
I'm trying to pass a defined variable in a BASH CURL command. I can't seem to get the single quotes or double quotes correct and it results in an error: line 22: --user: command not found Hardcoding the value is no problem. What I have...
1 Nov 2021 by Richard MacCutchan
It is because of the uncontinued blank line and the single quotes around $password. The following works*: curl "https://somewebsite.com" \ --request POST \ --header "Accept:application/json" \ --header "Content-Type:application/json" \ --data...
18 Jan 2020 by Member 14720175
Hello, I'm a beginner in programming and I'm having trouble writing a script. Write a script with two parameters: file name mask and directory name. The script's task is to display a list of file names from the given directory, matching the given mask together with the name of the owner and his...
18 Jan 2020 by k5054
Pay attention to your spaces and capital letters What you want is something more like #!/bin/bash find "$1" -name "*.$2" -exec stat -c "% N % u% U" {} \; I have not tried this to find out if it does what you want, or to find out if the call to stat is right, but note the lack of spaces and...
13 Oct 2021 by wifinut
I'm trying to remove the HH:MM:SS section in the following string example: Mar 6 01:00:53 2026 The problem is that I cannot go by character position because the text length can change. Example, there could be 16th instead of 6. Therefore I need...
13 Oct 2021 by Peter_in_2780
date2=$(echo $date1 | awk '{print $1 " " $2 " " $4}')
13 Oct 2021 by k5054
You're really close: date2=$(echo $date1 | cut -f3 -d\ ) should do the trick. In this case we're telling cut to return the 3rd field (-f3 flag), with field separator space, (-d\ flag ). Note that for the -d flag you need to make the space...
18 Jul 2021 by wifinut
I'm trying to add a speed test to my BASH script. I know you can install speedtest-cli on the host, but this is not an option. I'm looking for options perhaps using the CURL command. What I have tried: I tried using a CURL command to obtain the...
18 Jul 2021 by Daniel Pfeffer
Working backwards from the numbers that you give, we get 1 block = 100Mb / 22355 = 4473 bits. This looks close to a 4 Kb (i.e. 512 byte) block size. Adding various header and framing bits make the correspondence even better. I expect that you...
16 Oct 2021 by wifinut
I need to compare today's date in Epoch time to another Epoch date stored in a variable. I can store today's epoch in a variable with no problem. I run into trouble when I try to store a derived $cert_experation_epoch. This is most likely a...
16 Oct 2021 by Peter_in_2780
cert_expiration_epoch=$(date +%s -d "$cert_expiration") You really should start using the basic tools available. date --help man date man bash Also as someone else already told you, it's much better to use $(command) rather than `command`
9 Aug 2021 by wifinut
I'm trying to use Linux CURL command in my shell script where I make a conversion from Bps to Mbps to get the internet speed. However, the speed is not accurate. For example, my 100MB internet connection shows initially ~83Mbps. If I run the...
25 Jan 2022 by Member 15513062
I tried to increase the no. of records per run and computed for records/sec == throughput, ofcourse given the time_total. And expect curl to increase throughput per run, which explains the increase per run, in this case. When i plot Bytes...
24 Mar 2021 by wifinut
I'm trying to scan a text file for values that match some values that I obtain earlier. For clarity I'm statically assigning them here. The input file is a CSV but doesn't contain any commas. I'm open to using a plain text file if that helps. ...
24 Mar 2021 by k5054
Problem one seems to be a mix of UTF-8 and ASCII quotation marks (") in your code -- assuming you did a cut&paste from your source. Next, your logic is slightly off. You break the while loop and report no matches on the first non-match. One...
22 May 2022 by Phoenix Liveon
We have this "Continuing Lines" in Linux, with '\' #inside of a bash file command \ \ \ ... what about the Windows own implementation? What I have tried: inside of .bat file, I...
25 Apr 2022 by OriginalGriff
It's the "^" character, but it must be the last character on the line: it can't be followed by a space or anything else. Try it: WINKEY+R, "cmd" ENTER "cd^" It will respond "More?" "\" ENTER The current directory will chance to root. Yes, it...
10 Oct 2018 by Dave Kerr
A portable and magic-free way to open Pull Requests from the command line
1 Aug 2020 by cats n dogs
Hello, i have a list of keys on which i iterate and each time they current is not found in the json object i want to append it to the object. What I have tried: Here is what i have done so far https://jqplay.org/s/risDCfxm5j The problem is...
1 Aug 2020 by p e a k
The key is reduce. The following variant of your jq program produces the output shown below: reduce ("secrets","toto","test") as $k (.; if index($k) | not then . + {($k): $k} else . end) Output: { "config-maps": [ { ...
11 May 2023 by Rahul VB
Hello All, I am facing an unusual problem, i am trying to pass arguments to a build script through Jenkins command line, however i am not able to do so. When i capture and print the arguments it prints empty. Brief code is: argument=$1 echo...
20 Apr 2021 by Padala Vamsi ujpNQUXGRi
I made a c program which takes two standard inputs automatically and one manually. #include int main() { int i, j; scanf("%d %d", &i, &j); printf("Automatically entered %d %d\n", i, j); int k; ...
20 Apr 2021 by k5054
When you use a Here Document, the shell effectively does echo -e "1\n2\n" > /tmp/tempname ./test
20 Apr 2021 by Padala Vamsi ujpNQUXGRi
I found solution we can simply use Process Substitution. cat
22 Sep 2018 by Vaclav_
I have copied the following from LibreOffice and used "best guess" feature to post it. Hope the formatting pass. I am using the following function to output current line of bash -x debug script. echo_line_no () { grep -n "$1" $0 | sed "s/echo_line_no//" # grep the line(s)...
12 Aug 2017 by Rev7
I have a file with the following content 1,000 2,0001 300 4 I am trying to sort it numerically. What I have tried: sort -n filename sort -g filename
23 Feb 2024 by GiulioRig
hi guys i have a function in bash , for me is correct but i dontknow why continue to tell me ./BBSW.sh: 17: Syntax error: Bad for loop variable anyone can confirm me if is ok or not? urlencode() { local string="$1" local...
23 Feb 2024 by Richard MacCutchan
See https://stackoverflow.com/questions/30358065/syntax-error-bad-for-loop-variable[^]
21 Sep 2018 by Vaclav_
I just started using bash scripting language and having trouble understanding "command substitution " and " redirection". I am using bash man very frequently and know something about this specific subject. Here is an example of using command substitution. I used command "sed" to find line...
21 Sep 2018 by Richard MacCutchan
OK, to continue from my earlier message: 1. "Yes, I did try "redirection" but it did not work as expected." This is one of the most frustrating comments that we see in a question. We have no idea what you did expect to see or happen. And we have no idea what did happen. Without a clear...
15 Apr 2024 by Piniyi
Hello, I'm looking for help to design a bash script to locally backup a MySQL database and copy it to a network share. Ideally a retention option of X day(s) would be welcome. I have no knowledge of computer language. Your help is sincerely...
14 Apr 2024 by OriginalGriff
This isn't a "code to order" website - I suggest that if you can't do it for yourself (and are unwilling to learn how) you try somewhere like Freelancer.com - but be aware: you get what you pay for. Pay peanuts, get monkeys.
14 Apr 2024 by Pete O'Hanlon
This is the type of question that you could probably get answered using something like ChatGPT or Google Gemini. You have the information you want in your question, so what you need to do is write a prompt that will give you a suitable answer....
23 Jun 2015 by Aiden.JP
I'm trying to make this bash script dispatch and email when it detects that a certain type of file (files ending in ".gz"), which was last modified 24 hours ago, is below a certain size in a directory, I currently have it running on my entire computer. (I have it set to 10 kilobytes).It just...
23 Jun 2015 by Richard MacCutchan
It is some time since I wrote any bash scripts but I think you may need something like:#!/bin/bash# find all .gz files of 10k since yesterday, and count themcd COUNT = `find . -name "*.gz" -size -10k -mtime -1 -print | wc -l`if [ $COUNT -eq 0...
7 May 2012 by Sicppy
I am making a sort of Stereotypical english to russian translator, when I do: read -p 'Wanna learn russian? Type in an english phrase!: ' ENGecho $ENG | sed 's/ //g'It echoes the sentence perfectly fine with no spaces in the sentence. But when I try to do this:read -p 'You wanna learn...
7 May 2012 by Sergey Alexandrovich Kryukov
Out of curiosity, I tried to see how your sample phrase is translated into Russian, in your original form (slightly fixed) and also its equivalent in formally correct English:Wanna learn Russian? Type in an English phrase!orDo you want to learn Russian?Type in an English phrase!and...
8 May 2012 by Hex01
Instead of:ENG=$ENG | sed 's/ //g'try:ENG=`echo $ENG | sed 's/ //g'`Note that this uses back-quotes after the equal sign and the last character.
26 Jul 2022 by Goutham GSK
Hello Everyone, I am trying to read a file which contains numbers(Floats and integers) line by line, I am able to read the line correctly and it works fine, but when I try to compare it with a different number I am failing at that point ...
26 Jul 2022 by k5054
You can use normal comparison operators inside a bash [[ ]] expresion. Try if [[ $line > 30 ]]; then ... fi
18 Sep 2012 by John Atten
CodeProjectWhile there are GUI interfaces available for GIT (some good, some bad), familiarity with at least the basics of git’s command line interface can only enhance your ability to use the tool to maximum effectiveness.
3 Mar 2024 by GiulioRig
Hi , i try to modify this example api-usage-examples/V5_demo/api_demo/Encryption_HMAC.sh at master · bybit-exchange/api-usage-examples · GitHub[^] wiht this code _ByBit_PlaceOrder1() { # Read Bybit API keys and set them as global variables...
8 Mar 2024 by Member 16218405
Hi, So far I can only spot that you are using $URLPART2 in the definition of ORIGINAL_STRING before it is filled in with values (so URLPART2 is empty at this time). If is shall be empty, omit it, if it shall be populated, use it once it is...
7 Oct 2014 by Jaxam
In a command prompt I can type "ipconfig" and a list of internet information will appears. I want to do this in a C# console program. Basically, I want to run the C# program and I want to read and store everything that is given in "c:\ipconfig"."ipconfig" is a String in which that I can set...
7 Oct 2014 by User 11060979
You can use the class Process and Redirect Input and Output of cmd.exe.More or less an easy Thing, simply read the doc in MSDN an Play a Little bit.BTW 1.) it is not DOS it is as you mentioned also "command prompt". BTW 2.) There are other/better ways to get the same...
7 Oct 2014 by PIEBALDconsult
My ProcessCommunicator[^] article may give you an idea of how to do that and some of the pitfalls.I'd also like to point out that maybe the console app that processes the output needn't actually execute the command. You can write a processor app that reads its input from a...
7 Oct 2014 by Sergey Alexandrovich Kryukov
This application should not be in C:. Do you know that a system does not even have to have drive C?!And this is not a "DOS command". In modern OS, there is no such thing.Simply use System.Diagnostics.Process.Start with redirection of...
7 Oct 2014 by Maciej Los
Why to torture yourself by sending some command to the 'command prompt'?Isn't better to use .net classes, objects?Please, see:Network Programming in the .NET Framework[^]NetworkInterface Class[^]Quite often used alternative is WMI[^], which provides functionality to get information...
7 May 2023 by ToughDev
This post shows a way to change the default crontab editor in bash shell for Raspberry Pi.
3 Aug 2019 by Benktesh Sharma
How to combine multiple git commits into a single commit in GIT using Squash
21 Mar 2022 by RasatPC
How to combine command diff with sed (or other commands) to solve this question? FileRemote includes new lines that will be added to FileLocal in specific places. FileRemote: ## Functions Read Auto Hide List #101 Read Auto Move Win #102 # Read...
21 Mar 2022 by Luc Pattyn
Maybe this article is a good starting point: LPTextFileDiff: another textfile compare utility.[^] :)
22 Mar 2022 by RasatPC
Got the solution that works but is clumsy. awk '{print $1 " " $(NF)}' FileLocal.txt > output.tmp grep '^Read' output.tmp > output2.tmp Output2.tmp (result): Read #101 Read #202 Read #301 sed -i 's/Read/# Read/g' FileRemote.txt sed -i 's/# #...
29 Sep 2013 by Strider87
Hello All,I need to take user input value into the system and convert it to a time format.as an example :- if user input value as 3, i need to convert this value into 3 hours.Is this possible in shell scripting.Thank you,
17 Aug 2017 by D4rkTrick
How to create a web control panel for sound and lights for your Parrot drone (Wi-fi connected)
20 Apr 2020 by phil.o
Here are a few examples: Bash Infinite Loop Examples - nixCraft[^]
4 May 2018 by Member 13811640
Hello, I am new to Xlib, so don't know pretty much all of it. :D I would like to create a window frame across the screen, just that, just a window frame (something like the border of the marquee when you select with the mouse). I like that window frame to show up on the screen, let's say in...
4 May 2018 by Richard MacCutchan
Here you go: The Xlib Manual[^]
25 Oct 2016 by Ahmed Khateeb
In this article, I will describe how to Create WordPress Bitnami VM, how to connect to VM, how to add Custom Domain to that VM and important steps to follow after fresh installation.
11 Mar 2022 by RasatPC
I need help with a bash script modification. Currently, the script reads the values of file "Install.txt", (sample content): TRUE 203 TRUE 301 TRUE 602 TRUE 603 The numbers correspond with the same number in file: "ExtraExt.sys", (sample...
10 Mar 2022 by RasatPC
> @Richard MacCutchan: I do not think you can do it with simple sed... I have this solution but it is too complex. search=$(awk 'BEGIN{OFS=ORS=""}{if(NR>1){print "|"}print $2;}' Install.txt) sed -r "s/^false (.*($search))$/\TRUE/g" ExtraExt.sys...
11 Mar 2022 by RasatPC
I got one good solution. awk ' NR==FNR {a["#"$2] = $1; next} $NF in a {$1 = a[$NF]} 1' Install.txt ExtInstaller.sh RESULT same as Solution 1.
29 Jan 2015 by fausthsu
Does WebHDFS support HAR access?I'm programming a remote control script, and I've searched a lot and made some test, seems it does not?thanks.
11 Jun 2017 by Dave Kerr
Text in the command line can quickly get unwieldy. Here are some simple tricks you can use to navigate in the command line.
25 Mar 2018 by Dave Kerr
In this article, I'll show you how you can use the shell as an efficient tool to compliment how you use the clipboard.
22 Dec 2016 by Member 12917493
Hello everybody,I have been working with Debian for a couple of months for school and because it seems really handy to work with. but now I want to make a game for in the terminal. A Higher or Lower card game (also for school but I wanted to make it before I was given this task). You have to...
22 Dec 2016 by Jochen Arndt
I did not checked all the code but this looks suspicious:if [ "$score" -ge 1 ]; then Number=$(($RANDOM % 52)) Gokkaart=${KAARTEN[$Number]} oldNumber=$Number echo "De kaart is $Gokkaart2"fiYou are assigning a new random number to $Number. So the old number is no longer...
10 Feb 2019 by User 13204940
Hi, I've been able to compile and run Java code just fine, until I implemented JSON. I downloaded json-20180813.jar, and can't get it to be recognised. My file structure is as follows; /var/www/html/game/server/ : build (dir) run ClientConnection.java Main.java Server.java Utils.java...
21 Dec 2020 by Juljan Haka
Hello, i am kind of a junior developer so please forgive my ignorance. I am using Ubuntu LTS 20.04 at the moment. I have a python script with 4 functions in it. Each function has more than 3 variables. At least on of those variables in each...
5 Nov 2023 by V. Subhash
A simple fix for excessively bright video and low-volume audio
16 Jul 2020 by cassert24
A single-script git bisection utility wrapper for memory corruption bugs
4 Nov 2014 by Robert-68
Hello friendsit is too long time I don't code :-(I'm landed today on this cool community.I need realize (or thank you if you want to provide one) an utility that would count how many blank sectors (blank is meant that for the given sector, each of the 512 bytes is x00) are present in...
21 Jan 2014 by Member 10066562
i am working in iPad application automation. Now i am facing a problem that how can i check that my application is running that is automate in iOS Simulator(iPad/iOS 6.1) using bash script. My OS is Mac OS X (Version: 10.7.5). Please help.
24 Nov 2022 by domestic ivy
i am in directory a. Under directory a there is a fixed directory b. There are d{091....099} directories under the b directory. There are also different *.gz files under this d directory. I need to extract data from these files (filenames) and...
12 Oct 2013 by Member 10272533
I have some problem with bash script.I've got a string which has some repeated patterns like this.1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 ...Each fields is separated by tab key.I want it to look like this...1 2 3 41 2 3 41 2 3 4...How can I solve this problem using bash...
14 Oct 2013 by 101zeeshan101
You can use sed like this:Solution:s='1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4'p='1 2 3 4'echo "$s"|sed "s/$p\s*/&\n/g"1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4You can use infinite while loop and use the input file and iterate through each line to use this logic for murtiple lines.Live...
18 Feb 2024 by GiulioRig
hi guys i have a code this code print this https://api.binance.com/api/v3/ticker?symbols=["BTCUSDT","BNBBTC",]&windowSize=1d&type=full i want remove the last comma inside a square parentesis i want somthing like this ...
18 Feb 2024 by OriginalGriff
Use string replace: How to Replace Substring in Bash Natively[^] The string to search for: ",] The string to replace it with: "] If the "spare comma" is there, it'll be removed. If it isn't, the string will be unchanged.
19 Jan 2022 by mohamed abubeker
shopt -s dotglob nullglob shopt -s globstar for pathname in CWFiles/**/*.txt; do [ ! -f "pathname" ] && continue while read -r line do result=(( "$result" + "$pathname" )) echo $result done
19 Jan 2022 by k5054
What you have posted here make no sense. As written, this line result=(( "$result" + "$pathname" )) , seems to be trying to accumulate something to result, but since you have for pathname in CWFiles/**/*.txt then pathname will hold a value...
22 Mar 2022 by DrewMc
I've been trying to write a regex pattern to only match top level domain using bash i.e person@email.com or person1@email.uk would be valid but person@email.co.uk would be invalid. What I have tried: grep -E -o...
25 Nov 2020 by OriginalGriff
It's a bad idea. But ... ^([a-zA-Z0-9_\-\.]+)@[^\.]+\.[^\.]+$ Will do it. You'll be eliminating a heck of a lot of valid emails though! (And letting bad ones though as well ...) If you are going to use Regular Expressions, then get a copy of...
19 Sep 2014 by Anand Shaw
Hi,I want to store welcome message to a file when I do SSH to a unix server.Please tell me how can I redirect the message to a file.Thanks.
19 Sep 2014 by Richard MacCutchan
cat /etc/motd > somefilename
4 Feb 2013 by coffeenet
HiI need to input this command, it is written in bash, but I my terminal is zsh. How do I rewrite it?ssh username@rserver.com -L 127.0.0.1:8888:*:11111Thanx!
10 Nov 2014 by Member 10440553
How do I sed to retrieve URLs within single quotes?Currently, it can only retrieve URLs which starts with HTTP/HTTPS.urls=$(sed -ne 's/.*\(http[^"]*\).*/\1/p' 's/.*\(https[^"]*\).*/\1/p' /url/to/path)
11 Nov 2014 by Member 11224763
Hello,I have a project where I have to show the current temperature on a website.I already created a script in bash that "echo" me the current temperature, but I don't really know how to display that result on my website.Sincerly,Yvan MLS
11 Nov 2014 by Dominic Burford
There may be other ways of doing this, but you could consider using the XMLHttpRequest object as in the example below.xmlhttp=new XMLHttpRequest();xmlhttp.open("GET","temperaure.txt",false);xmlhttp.send();document.getElementById("temperature").innerHTML=xmlhttp.responseText;
12 Apr 2024 by V. Subhash
Compile FFmpeg v7.0 CLI from source and check out some of its new features
7 Apr 2022 by Chris Maunder
A quick overview and a simple bash script to make your script output a little more lively
8 Mar 2023 by V. Subhash
How to get compile the latest FFmpeg source code and try out some new features
17 May 2021 by Aman Parmar
a)I want to connect to MongoDB b)Surround Mondodb with try-catch block c)catch exceptions. I have to use git to get the latest branch. I have assumed that the below command will run before MongoDB connection: source setenv.sh source...
2 Nov 2015 by Member 10308543
Hey guys,I am working on an Illustrator extension project which uses HTML5 for UI and JavaScript for implementing functionalities.Apart from HTML5 I am also using JQuery and AngularJS.Illustrator SDK has an special feature where you can execute a process using it.I need to pack a PDF...
19 Sep 2014 by Anand Shaw
Hi,As a user to a linux server, I don't have access to shadow file. But I want to find out password expiry details for my username.Thanks.
5 Aug 2023 by headshot9x
Hi, I have log files coming from other servers, the content in file something wrong and I want to rewrite content before move file. I'm not familiar with shell script in linux, but I tried research and learn around. So, I have idea about, but so...
30 May 2020 by M.S.S.E
when I use the command to get the file size in bye using wc -c the command return two values, the size in byte and the file name, ex: the output for wc -c my_file is 322 my_file I need to get only the first value to use it if condition, and I...
30 May 2020 by phil.o
You can pipe awk[^] to isolate the size: wc -c my_file | awk '{print $1}'
30 May 2020 by k5054
There is no option not to print the file name, you'll need to use a pipe as phil.o showed. Some other options: #use cat cat my_file | wc -c #use cut wc -c my_file | cut -f1 -d ' ' #you could also use stat, if you don't want to use a pipe ...