programming

Compare Numbers in Bash

Compare integers in Bash with -eq, -gt, [ ], [[ ]], and (( )); handle leading zeros, negative values, untrusted input, and decimal checks with bc or awk.

Deepak Prasad10 min read
programming

Check If File or Directory Exists in Bash

Check whether a file or directory exists in Bash with -e, -f, and -d, including missing paths, symlinks, permissions, and practical shell script examples.

Deepak Prasad9 min read
programming

Compare Strings in Bash

Compare strings in Bash with =, ==, !=, -z and -n. Learn empty vs unset values, substring and glob matching, case-insensitive checks, and lexical ordering.

Deepak Prasad11 min read
programming

Bash [ ] vs [[ ]] vs (( ))

Learn when to use Bash [ ], [[ ]], and (( )) for tests: POSIX test syntax, Bash conditionals, pattern and regex matching, numeric comparisons, and common failure examples.

Deepak Prasad12 min read
programming

Bash case Statement with Examples

Learn how to use the Bash case statement with practical examples, match multiple values and wildcard patterns, add a default case, and compare case with if/elif.

Deepak Prasad10 min read
programming

Bash if, elif, else with Examples

Learn Bash if, elif, and else syntax with examples for variables, multiple conditions, command exit status, nested if statements, and common errors.

Deepak Prasad10 min read
programming

Bash Arithmetic: $(( )), (( )) and Decimal Math

Learn Bash arithmetic with $(( )) and (( )), including operators, integer division, counters, number bases, and floating-point calculations with awk and bc.

Deepak Prasad10 min read
programming

Bash Exit Codes: $?, exit and Common Status Codes

Learn how Bash exit codes work, check the last status with $?, use exit, understand codes 0, 1, 126 and 127, and handle pipeline failures with PIPESTATUS and pipefail.

Deepak Prasad10 min read
programming

Concatenate Strings in Bash

Concatenate strings in Bash with adjacent expansions, ${var} brace boundaries, += append, separators, printf -v formatting, and safe patterns for command output and loops.

Deepak Prasad7 min read
programming

Get Bash Script Directory, Path and Name

Get the Bash script name, absolute path, and directory with $0, BASH_SOURCE, dirname, cd+pwd, and GNU readlink -f — including sourced files and symlinks.

Deepak Prasad9 min read
programming

Bash echo vs printf: Output and Newlines

Compare Bash echo and printf for newlines, prompts, columns, and portable scripts: echo -n, echo -e pitfalls, printf format strings, printf -v, stderr output, and safe printing of variable content.

Deepak Prasad7 min read
programming

Bash Script Arguments: $1, $#, $@, $* and shift

Learn Bash script arguments with $1, $#, $@, $*, shift, and ${10}. See how quoting preserves filenames with spaces, validate argument counts, and forward args safely to cp and other commands.

Deepak Prasad10 min read
programming

Bash read Command: Get User Input

Learn the Bash read builtin for interactive input: read into variables, use -r by default, prompt with -p, split fields with IFS, hide passwords with -s, time out with -t, and read arrays with -a.

Deepak Prasad14 min read
programming

Bash Environment Variables: Set, Export, List and Unset

Learn how Bash environment variables work with export, env, and printenv, how child processes inherit them, and how to set, list, unexport, and unset variables.

Deepak Prasad10 min read
programming

Bash Startup Files: .bashrc vs .bash_profile vs .profile

Learn when Bash reads .bashrc, .bash_profile, and .profile on login and non-login shells, how SSH and cron differ, what BASH_ENV does, and where to put PATH, aliases, and exports.

Deepak Prasad13 min read
programming

Bash Single vs Double Quotes: Differences and Examples

Compare Bash single vs double quotes with tested examples. Learn variable expansion, escaping quotes, $'...' syntax, globbing, filenames with spaces, and safe variable quoting.

Deepak Prasad10 min read
programming

Bash Variables: Create, Assign, Use and Unset

Learn how to create, assign, expand, quote, unset, and protect Bash variables with declare and readonly, plus how unset differs from empty and when to use ${var}.

Deepak Prasad9 min read
programming

Bash Comments: Single-Line, Inline and Multiline Examples

Learn Bash comment syntax with #, inline comments, quoted hash characters, multiline comments, heredoc workarounds, and how shebang lines differ from ordinary comments.

Deepak Prasad8 min read
programming

Bash vs sh: Differences and Which Shell to Use

Compare Bash vs sh with tested examples. Learn POSIX portability, Bash-only syntax, what /bin/sh runs, and when to use #!/bin/bash or #!/bin/sh.

Deepak Prasad14 min read
programming

Bash Shebang Explained: #!/bin/bash vs /usr/bin/env bash

Learn what a Bash shebang does, how #!/bin/bash differs from #!/usr/bin/env bash, when the shebang is ignored, and which one to use in shell scripts.

Deepak Prasad11 min read
programming

How to Write a .bat File

Learn how to write a .bat file on Windows, from echo and variables to arguments, loops, delayed expansion, exit codes, and a complete logging backup script you can adapt.

Deepak Prasad18 min read
programming

Python Rename File

Learn how to rename a file in Python with pathlib Path.rename(), Path.replace(), os.rename(), os.replace(), and shutil.move(), including extension changes, batch renames, overwrite rules, and cross-filesystem moves.

Deepak Prasad18 min read
programming

Golang Time Format: Format, Parse, and Layout Examples

Learn Go time formatting and parsing with the reference date 2006-01-02, RFC3339, DateOnly, time.Format, time.Parse, ParseInLocation, and timezone layouts.

Tuan Nguyen8 min read
programming

Golang Time Package: time.Now, Duration, Parse, and Date Examples

Learn Go's time package with examples for time.Now, UTC, Duration, Add and Sub, Unix timestamps, time zones, Format, Parse, Sleep, Timer, and Ticker.

Tuan Nguyen11 min read
programming

Convert String to uint8 or byte in Go

Convert a Go string to uint8 using strconv.ParseUint, validate the 0–255 range, and learn the difference between parsing numeric text and reading a string byte.

Tuan Nguyen7 min read
programming

Import a Struct from Another File or Package in Go

Learn how to use a Go struct defined in another file, import an exported struct from another package, and fix undefined errors caused by go run main.go.

Tuan Nguyen7 min read
programming

Convert int to int64 and int64 to int in Go

Convert int to int64 and int64 to int in Go, understand 32-bit vs 64-bit int sizes, check values before narrowing, and choose the correct integer type.

Tuan Nguyen5 min read
programming

Golang Kill Process by PID: Kill, Signal, and CommandContext

Learn how to kill a process by PID in Go, stop exec.Command children, use Process.Signal vs Kill, handle timeouts with CommandContext, and avoid orphan processes.

Tuan Nguyen9 min read
programming

Golang `io.ReadCloser`: Read, Close, `NopCloser`, and Convert to String

Learn how io.ReadCloser combines Reader and Closer in Go, how to close HTTP response bodies, wrap readers with io.NopCloser, and read content with io.ReadAll.

Tuan Nguyen5 min read
programming

Fix Go "package is not in GOROOT" and "cannot find package"

Fix Go "package is not in GOROOT", "cannot find package", and missing module errors by checking go.mod, import paths, workspaces, dependencies, and GOPATH mode.

Tuan Nguyen9 min read