Click here to Skip to main content
15,891,033 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 Updated

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...
26 May 2015 by _Asif_
I have not tried it myself but it seems that this could help you out[^]
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.
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...
25 Aug 2013 by AjithKp560_
Python is not a shell. It is programming language. You can program many exploits using this programming language. So, the exploits that will spawn control over remote computers are also called as "SHELLS". Like this you can program exploits using perl, ruby, php like programming languages......
22 Feb 2017 by Albert Holguin
So, that doesn't appear to be valid bash code, starting a line with "58..62" is invalid, as it's not a command or shortcut... but if it's pseudo-code I'd guess it's attempting to run nslookup on a range of IP addresses.This gets you the same thing that your code appears to be attempting to...
23 Nov 2016 by Alexander Mills
I have a node.js script and I want both stdout and stderr to go to a log file, but I want to pass the stdout and stderr through grep first.This works: node a.js > a.log 2>&1But this doesn't:node a.js | grep "error" > a.log 2>&1It doesn't output anything to the file, but worse...
24 Jun 2014 by Alexander24
I am trying to send an email with attachment remotely using cywing. The code below works perfectly with a plain text email. I have tried a few methods a found on the internet, but they don't work. Please can anyone help me#!/bin/bashecho This is a testing email | email -s "hi"...
26 Jun 2014 by Alexander24
I have installed all the dependencies in cron. My scripts are working properly, and also I have tested cron which I think works properly as well. However, I would like to set up a task to run a script file. Here is where I need help, please can anyone provide me some help? Here is cron code: My...
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...
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 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.
21 Oct 2013 by Andreas Gieriet
The task sounds non-sense to me.Running a process in background means:the stell starts that command as background process (fire and forget) and immediately continues with the next command.I.e. this completes instantly:sleep 100 &echo "done"You may observe the sleep process by...
29 Dec 2011 by Be Yourself
I have two solaris servers having IP10.10.36.20(A) and 10.90.33.22(B)The server B is exposed to internet but server A is intranet server.I want to transfer some files from server B to server A but in order to do this I have to bypass the firewall installed in server A which can raise...
20 Jan 2012 by Be Yourself
I have a java class to be scheduled in the server to be run in a specified time .Can any one help me how to schedule a execution of a java class in server .I have tried goggling for it but I didn't find any fruitful results.The server is apache server.
29 Jan 2012 by Be Yourself
I have a jar file named main.jar with the Manifest entry as:Main-Class : tss.ReportClass-Path : lib/Classes12.jar lib/xlist.jar lib/axis2.jarnow I have the lib folder in the same directory as that of the jar file and I am able to run the jar also from command prompt by using "java -jar"...
3 Aug 2019 by Benktesh Sharma
How to combine multiple git commits into a single commit in GIT using Squash
16 May 2021 by bob_smith_0101
To familiarise myself with crontab, I scheduled an echo command to run and create a file in a user's home folder (report.txt) and also in a second user's account. Example: * * * * * echo "command" >> /home/user/report.txt * * * * * echo...
16 Jul 2020 by cassert24
A single-script git bisection utility wrapper for memory corruption bugs
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...
7 Apr 2022 by Chris Maunder
A quick overview and a simple bash script to make your script output a little more lively
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 Sep 2023 by ColdSnus
I am currently working on a bash script and I need a regex that allows only lowercase alphanumeric, hyphen and dots. Please help me! What I have tried: So far, I have tried this: "[a-z-]+"
17 Aug 2017 by D4rkTrick
How to create a web control panel for sound and lights for your Parrot drone (Wi-fi connected)
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...
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.
10 Oct 2018 by Dave Kerr
A portable and magic-free way to open Pull Requests from the command line
12 Sep 2014 by DaveAuld
I think this answers your question.http://stackoverflow.com/questions/12340846/bash-shell-script-to-find-the-closest-parent-directory-of-several-files[^]
11 Feb 2022 by DoingWork
I want to start 2 applications with one shortcut. One application is GUI based while other is shell based (Terminal=true in .desktop file). What I have tried: For this goal, I created a file name **Starter** having following script in this...
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...
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;
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...
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.
21 Mar 2023 by GiulioRig
hi is possible insert inside of gui created in zenity the combobox for choice what i want ? What I have tried: i try to code but not work #!/bin/bash # Definisce la dimensione della finestra width=800 height=900 # Array contenente le opzioni...
21 Mar 2023 by GiulioRig
look help nanual in shell and you see : zenity --help-all Usage: zenity [OPTION…] Help Options: -h, --help Show help options --help-all Show all help options ...
12 Feb 2024 by GiulioRig
Hi why my code tell me Error: in prepare, no such table: BinanceCex i have the table i am sure maybe i did do some error in script bash ? #!/bin/bash set -x #RunProgram() { # Aggiungi qui la logica per eseguire il programma #} #...
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 ...
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...
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...
31 Mar 2024 by GiulioRig
Hi i have this script in bash for huobi exchange (https://www.htx.com/en-us/opend/newApiPages/?id=419[^]) #!/bin/bash # Set API keys access_key="" secret_key="" host="api.huobi.pro" path="/v1/account/accounts" method="GET" # Generates a...
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 ...
31 Dec 2011 by Graham Breach
Do a search for "ssh certificate based authentication" - as long as it is enabled, key-based authentication should allow you to use scp between trusted hosts.
14 Oct 2020 by h_wiedey
Using file name databases on MacOS Unix
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...
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.
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...
19 Apr 2017 by jena_m
i tried running this scriptkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk ! What I have tried:
23 Nov 2016 by Jochen Arndt
Just redirect stderr to stdout before piping to grep:node a.js 2>&1 | grep "error" > a.log When using bash, there is a shorthand for the above:node a.js |& grep "error" > a.log With |&, stdout and stderr of the first command are piped to the second. See the Bash Reference Manual[^].
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...
4 Apr 2018 by Jochen Arndt
When you need to include a double quote within a string, you have to escape it as described at PHP: Strings - Manual[^]: exec("sudo tshark -n -r $filename -R rtp -R \"rtp.ssrc == $ssrc\" -T fields -e rtp.payload | tee payloads"); The for loop requires understanding the bash commands: BASH...
12 Jun 2018 by Jochen Arndt
It is never a good idea to execute an application when not knwowing what it does (especially by passing command line options). Do such at least as normal user and not as root. With many applications there is a man page installed too. So you should first try if such is available: man scan and...
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.
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...
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...
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 ...
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...
20 Apr 2021 by k5054
When you use a Here Document, the shell effectively does echo -e "1\n2\n" > /tmp/tempname ./test
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...
6 Jan 2022 by k5054
Parsing JSON using standard tools (grep, awk, sed, etc), is probably more difficult than you imagine. You really need a JSON parser. This is discussed here: bash - Parsing JSON with Unix tools - Stack Overflow[^] Looking at the home page for ...
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...
26 Jul 2022 by k5054
You can use normal comparison operators inside a bash [[ ]] expresion. Try if [[ $line > 30 ]]; then ... fi
8 Mar 2023 by k5054
How to update a bash variable inside a loop when reading from command output
8 Feb 2024 by k5054
Are you sure you have the BinanceCex table in the SQLite file ConfigDB.db? Check your db file $[k5054@localhost]$ sqlite3 ConfigDB.db .schema CREATE TABLE BinanceCex( id int, ... ); CREATE TABLE StampExchange( ... ); $[k5054@localhost]$ Are...
31 Mar 2024 by k5054
You bash script already seems to print out the URL it sends in send_request(), but I can't see that your python script does the same. The first thing I would do, is get the python script to print out the URL and compare. If you want to see...
26 Jan 2021 by Khairi Khaled
• In my work, network element configuration files downloaded automatically in hourly basis to the 3rd party server, I have configured the folder where the files downloaded on it as local Repo. • Recently, git schedule created to check the...
4 Mar 2018 by khorshidpour
what does : mean in the beginning of variable assignment? : ${var:=value} What I have tried: what is different between these two in bash script? : ${var:=value} ${var:=value}
21 Mar 2022 by Luc Pattyn
Maybe this article is a good starting point: LPTextFileDiff: another textfile compare utility.[^] :)
22 May 2018 by lukeer
Hi forum, a bash script I wrote behaves unexpectedly (read: "There's a bug in it.") and I just don't get it. Say there's that variable PAGES which contains " page0.pdf page1.pdf page2.pdf". And there is $1 which contains "result.pdf". I want to merge all those single-page pdf files into one...
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 M.S.S.E
I did it using this : wc -c
24 Jun 2014 by Maciej Los
Have a look here: Sending Emails with Attachments from the Command Line Revisited [^]As per i understand you need to install 2 packages (Email and MTA). After configuration, you'll be able to send email with attachment(s).
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...
23 Jul 2016 by magic_owl
for f in ./*.mp3; do sox "$f" "${f%%.mp3}processed.mp3" silence 1 0.02 1% -1 0.02 1%; doneThis is a script I'm using to process audio files. The problem is that it keeps going in a loop, processing the new audio files as well. I'd like to fix this by having the output go in a subfolder, so I...
27 Jul 2021 by Marchan4
My ruby ​​version is 2.6.6, my mysql version is 8.0.23, my mysql2 version is 0.5.3, my bundler version is 2.2.21, my rails version is 5.0.7.2, and my Xcode version is 12.5. I use macOS Big Sur(version 11.4) and the text editor "Atom". I'm...
6 Jan 2022 by mc96
So far my bash script is as follows: #!/bin/sh sessionnumber=0 curl --data '{"command":"listsessions","transaction":"123","adminsecret":"secret"}' -H "Content-Type: application/json" http://127.0.0.1:8088/admin This successfully returns the...
11 Jan 2022 by mc96
I have a bash shell script that performs a cURL command, and gets the raw output of an array inside the json array. I can also successfully echo the number of elements in the array Why can I not assign the amount of elements inside the array to...
11 Jan 2022 by mc96
SOLVED! realoutput=$(echo $output | jq '. | length') echo "OK|janusSessions=$realoutput" Produces: OK|janusSessions=2
24 Aug 2013 by Mehdi Gholam
Python is a programming language : http://en.wikipedia.org/wiki/Python_%28programming_language%29[^]However it can be used within a shell.
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.
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...
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...
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)
8 Sep 2014 by Member 10946242
Hi,I would like to ask how to get the 4th to the last value in a file. I don't have problem on extracting a value from the beginning of the file using this sed (e.g. sed -n 'p' filename) only have a trouble when parsing value using the last part of the file.
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
26 May 2015 by Member 11612625
stuck. very stuck. why? because i can't figure out a replacement command that works by giving an indexwhat i'm doing now is: rpl "oldstring" "newstring" "filename"ofcourse this changes all the search results. what i need is something like this: rpl "index" "newstring"...
28 Apr 2015 by Member 11649315
Tried finding an answer on stackoverflow but can't. All answers were with awk and sed which I'm not allowed to use! So once again, I ask you to help me.Basically I need to write a script that prints out the history of all used commands in the linux terminal. The commands are saved in a file...
23 Sep 2015 by Member 12006086
In JavaScript, what code do I need to implement Bzip2 in a browser in order to compress web pages on the fly?How can I also change the compression level of Bzip2 in source code?
11 Nov 2015 by Member 12131950
I have the following directory strucure: project root/ negatives/ the negatives files ngest/ 00palmo/ 1510 positives files 01pugno/ 1431 positive files 02indice/ 1073 positive files 03v/ ...
16 May 2016 by Member 12485314
i want to overwrite value of variable s1 from "abc" to ---> [more /home/mohsin/Desktop/system_usage_bash_file | grep TIME | awk 'BEGIN {FS=","} {print $3}']but when i echo i get "abc" on both echos,means it is not overwrittenWhat I have tried:#!/bin/bashs1="abc"s2="USED"echo...
29 Sep 2016 by Member 12767270
I am learning bash scripting and I am trying to understand how regex works with bash. In my simple program, I have a file of various different lines but want to match a simple int pair with the format of the two numbers separated by a comma and a space as so: 123, 123. I also want to match the...
3 Oct 2016 by Member 12773538
I have a bash script to login into one of my storage device and execute couple of commands and saves output into one text file. Here's the code.plink.exe -ssh root@10.10.10.10 -pw password1 "storage-controllers" >> Cluster1_%date:~-4,4%%date:~-7,2%%date:~-10,2%.txtecho. >>...
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 Feb 2017 by Member 13017232
58..62 | % { nslookup 192.168.1."$_"}I'm confused as to what the two successive periods represent. I understand the pipe and nslookup command but not the rest.Thanks.What I have tried:58..62 | % { nslookup 192.168.1."$_"}I'm confused as to what the two successive periods...
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...
12 Jun 2018 by Member 13820729
i wonder what does this command do, can any one know what is it about? What I have tried: i have tried it on mac bash terminal but i cant find out what it does
6 Nov 2022 by Member 14032085
I have a folder with 1700+ hyperlinks using the proprietary .webloc format created by the anti-standardizing Apple OS. I want to run a script which converts the lines to the standard format so that they will also run when clicked on a Unix, Linux, or TrueOS/FreeBSD/OpenBSD system. Search engines...
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...
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...