Turning a Common Terminal Mistake into a Feature

@thecrazygm · 2025-08-13 11:18 · Synergy Builders

Hey everyone,

Today's post is about a simple little shell script that solves a problem I'm sure many of us have run into. We've all been there: you're following a tutorial online and you blindly copy a command to paste into your terminal. The example looks something like this:

$ curl https://example.com

If you're not paying attention, you accidentally copy the $ prompt character along with the command. When you paste it and hit enter, your shell throws an error like $: command not found. It's a minor but frequent annoyance.


A Simple, Foolproof Solution

To solve this for myself, I wrote a simple script that I named $ and placed it in my path (~/.local/bin). Now, instead of an error, my shell gives me a helpful confirmation prompt. I call it the "Hey, you might have made a mistake" prompt.

Here's the script:

#!/usr/bin/env bash

# Simple command wrapper that confirms before running pasted commands

set -euo pipefail

main() {
  local status=0

  # Reconstruct the command as a safely quoted string for display
  local cmd_str=""
  for arg in "$@"; do
    if [ -z "$cmd_str" ]; then
      printf -v cmd_str "%q" "$arg"
    else
      printf -v cmd_str "%s %q" "$cmd_str" "$arg"
    fi
  done

  # Standard prompt and confirmation
  echo "It looks like you pasted a command prefixed with '$'."
  echo "Command:"
  echo "  $cmd_str"
  echo
  read -r -p "Do you want to run this command? [y/N] " reply
  case "$reply" in
  [yY] | [yY][eE][sS]) ;;
  *)
    echo "Canceled."
    return 0
    ;;
  esac

  # Execute the actual command
  "$@" || status=$?

  if [ $status -eq 0 ]; then
    echo "Command completed successfully."
  else
    echo "Command failed with exit code $status."
  fi
  return $status
}

main "$@"

Now, when I accidentally paste a command with a leading dollar sign, I get this instead of an error:

Hey dumbass, don't blindly paste things you see on the internet!

The script simply takes all the arguments passed to it (which is the command you intended to run), asks if you want to execute it, and then runs it if you confirm. It's a tiny quality-of-life improvement that turns a common mistake into a helpful interaction.

As always,
Michael Garcia a.k.a. TheCrazyGM

#dev #bash #archon #tribes #pimp #proofofbrain
Payout: 8.359 HBD
Votes: 198
More interactions (upvote, reblog, reply) coming soon.