Skip to content

Instantly share code, notes, and snippets.

View harishkannarao's full-sized avatar

Harish Kannarao harishkannarao

View GitHub Profile
@harishkannarao
harishkannarao / ffmped.md
Created September 8, 2026 10:00
Useful ffmpeg commands

Concat 2 video files of same video resolution and same audio codec

ffmpeg -f concat -safe 0 -i <(printf "file '%s'\n" "$HOME/Downloads/clip1.mov" "$HOME/Downloads/clip2.mov") -c copy $HOME/Downloads/output.mov

@harishkannarao
harishkannarao / windows_poweshell_jdk_switch_function.md
Created February 16, 2026 13:24
Windows Powershell / Terminal user function to switch Java JDK

Windows Powershell Commands

Check if profile exists

Test-Path $PROFILE

Create profile if it doesn't exist

Quitting
:x Exit, saving changes
:q Exit as long as there have been no changes
:wq Write and Quit. Saves any changes made to the file
ZZ Exit and save changes if any have been made
:q! Exit and ignore any changes
Inserting Text

Less Cheatsheet

less {filename}

Navigation
SPACE forward one window
b backward one window
d forward half window
@harishkannarao
harishkannarao / build-alpine-jre-docker.sh
Last active September 11, 2024 12:10
Build an alpine image with jq, curl and jre 11 from scratch without pulling from hub.docker.com
#!/bin/sh
# Make the script to abort if any command fails. Use set +e to change the behaviour and ignore failed command.
set -e
# Prints the commands as it is executed. Useful for debugging. Use set +x to disable debugging.
set -x
# Set default values
ORGANISATION_NAME="${ORGANISATION_NAME:-com.example}"
#!/bin/bash
# Make the script to abort if any command fails. Use set +e to change the behaviour and ignore failed command.
set -e
# Uncomment below line to print the commands as it is executed. Useful for debugging. Use set +x to disable debugging.
# set -x
# Source the functions from an url
source <(curl -s "https://gist.githubusercontent.com/harishkannarao/58d317f2743c842b5323165a492db81c/raw/75ee691d4d4568c59443a070c6e5d192d717b6bc/reusable_functions.sh")
#!/bin/bash
function add()
{
echo "$1 + $2" | bc -l
}
function subtract()
{
echo "$1 - $2" | bc -l

Bash Script loops and conditional statement example

The following blog post shows example of bash script with for loop, while loop, if elif else conditional statements.

Important aspects covered in the sample script:

  • Conditional while loop
  • While loop to iterate over lines in a file
  • Infinite while loop with break and continue
  • Infinite while loop with sleep
  • Iterate over arguments passed as input using for loop
  • For loop with counter
#!/bin/bash
# Make the script to abort if any command fails. Use set +e to change the behaviour and ignore failed command.
set -e
# Uncomment below line to print the commands as it is executed. Useful for debugging. Use set +x to disable debugging.
# set -x
echo "Example of numerical comparison with if elif else"
for (( c=-5; c<=5; c=$c+1 ))
#!/bin/bash
# Make the script to abort if any command fails. Use set +e to change the behaviour and ignore failed command.
set -e
# Uncomment below line to print the commands as it is executed. Useful for debugging. Use set +x to disable debugging.
# set -x
while [[ $# -gt 0 ]]
do