create account

Turning a Common Terminal Mistake into a Feature by thecrazygm

View this thread on: hive.blogpeakd.comecency.com
· @thecrazygm ·
$7.38
Turning a Common Terminal Mistake into a Feature
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:

```bash
$ 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:

```bash
#!/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!](https://files.peakd.com/file/peakd-hive/thecrazygm/Eo1wU86Pj3LfawJprhJwB8jbMjZNdbSW16EjjYjE9qDgQfW4kMD4hZRGrrpLzLBtwVG.png)

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
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 134 others
properties (23)
authorthecrazygm
permlinkturning-a-common-terminal-mistake-into-a-feature
categoryhive-186392
json_metadata{"app":"peakd/2025.8.3","format":"markdown","tags":["dev","bash","archon","tribes","pimp","proofofbrain"],"users":[],"image":["https://files.peakd.com/file/peakd-hive/thecrazygm/Eo1wU86Pj3LfawJprhJwB8jbMjZNdbSW16EjjYjE9qDgQfW4kMD4hZRGrrpLzLBtwVG.png"]}
created2025-08-13 11:18:42
last_update2025-08-13 11:18:42
depth0
children5
last_payout2025-08-20 11:18:42
cashout_time1969-12-31 23:59:59
total_payout_value3.400 HBD
curator_payout_value3.981 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,374
author_reputation122,979,132,462,946
root_title"Turning a Common Terminal Mistake into a Feature"
beneficiaries
0.
accountthecrazygm.bank
weight1,500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id144,954,270
net_rshares27,376,957,952,194
author_curate_reward""
vote details (198)
@ecoinstant ·
$0.03
This copy paste mistake I have actually made more than I care to admit!  I even remember figuring out what that dollar sign was all about 😅

!PAKX
!PIMP
!PIZZA
👍  ,
properties (23)
authorecoinstant
permlinkre-thecrazygm-t0yg3z
categoryhive-186392
json_metadata{"tags":["hive-186392"],"app":"peakd/2025.8.3","image":[],"users":[]}
created2025-08-13 23:05:00
last_update2025-08-13 23:05:00
depth1
children1
last_payout2025-08-20 23:05:00
cashout_time1969-12-31 23:59:59
total_payout_value0.012 HBD
curator_payout_value0.013 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length159
author_reputation878,239,309,108,880
root_title"Turning a Common Terminal Mistake into a Feature"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id144,976,181
net_rshares91,068,413,578
author_curate_reward""
vote details (2)
@pakx ·
$0.04
<center><table><tr></tr><tr><td><center><img src='https://files.peakd.com/file/peakd-hive/pakx/PakX-logo-transparent.png'><p><sup><a href='https://hive-engine.com/?p=market&t=PAKX'>View or trade </a> <code>PAKX</code> tokens.</sup></p></center></td><td><center>@ecoinstant, PAKX has voted the post by @thecrazygm. (1/2 calls)</p><br><br><p>Use !PAKX command if you hold enough balance to call for a @pakx vote on worthy posts! More details available on <a href='/@pakx'>PAKX Blog</a>.</p></center></td></tr></table></center>
👍  ,
properties (23)
authorpakx
permlinkre-ecoinstant-1755126342
categoryhive-186392
json_metadata"{"tags": ["pakx", "hivepakistan"], "app": "HiveDiscoMod"}"
created2025-08-13 23:05:42
last_update2025-08-13 23:05:42
depth2
children0
last_payout2025-08-20 23:05:42
cashout_time1969-12-31 23:59:59
total_payout_value0.018 HBD
curator_payout_value0.019 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length524
author_reputation165,760,400,741
root_title"Turning a Common Terminal Mistake into a Feature"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id144,976,189
net_rshares132,402,465,763
author_curate_reward""
vote details (2)
@pizzabot · (edited)
$0.02
RE: Turning a Common Terminal Mistake into a Feature
<center>PIZZA!


$PIZZA slices delivered:
steemmillionaire tipped thecrazygm 
@ecoinstant<sub>(1/20)</sub> tipped @thecrazygm 


<sub>Come get [MOON](https://moon.hive.pizza)ed!</sub></center>
👍  
properties (23)
authorpizzabot
permlinkre-turning-a-common-terminal-mistake-into-a-feature-20250813t215148z
categoryhive-186392
json_metadata"{"app": "pizzabot"}"
created2025-08-13 21:51:48
last_update2025-08-13 23:05:21
depth1
children0
last_payout2025-08-20 21:51:48
cashout_time1969-12-31 23:59:59
total_payout_value0.012 HBD
curator_payout_value0.012 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length192
author_reputation7,757,592,350,400
root_title"Turning a Common Terminal Mistake into a Feature"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id144,974,779
net_rshares87,460,124,400
author_curate_reward""
vote details (1)
@steemmillionaire ·
$0.02
Elegant solution! Love that you share these little puzzles!

!PIMP & !PIZZA
👍  
properties (23)
authorsteemmillionaire
permlinkre-thecrazygm-t0ycpr
categoryhive-186392
json_metadata{"tags":["hive-186392"],"app":"peakd/2025.8.1","image":[],"users":[]}
created2025-08-13 21:51:27
last_update2025-08-13 21:51:27
depth1
children0
last_payout2025-08-20 21:51:27
cashout_time1969-12-31 23:59:59
total_payout_value0.012 HBD
curator_payout_value0.012 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length75
author_reputation128,650,232,391,597
root_title"Turning a Common Terminal Mistake into a Feature"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id144,974,770
net_rshares85,710,985,922
author_curate_reward""
vote details (1)
@tydynrain ·
$0.02
That's a great simple and useful tool. Taking into account possible mistakes, and automating error checking and correcting, is brilliant, my friend. 😁 🙏 💚 ✨ 🤙 
👍  
properties (23)
authortydynrain
permlinkre-thecrazygm-2025813t214423723z
categoryhive-186392
json_metadata{"links":[],"type":"comment","tags":["hive-186392","dev","bash","archon","tribes","pimp","proofofbrain"],"app":"ecency/3.3.3-mobile","format":"markdown+html"}
created2025-08-14 07:44:24
last_update2025-08-14 07:44:24
depth1
children0
last_payout2025-08-21 07:44:24
cashout_time1969-12-31 23:59:59
total_payout_value0.012 HBD
curator_payout_value0.012 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length159
author_reputation211,715,020,170,703
root_title"Turning a Common Terminal Mistake into a Feature"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id144,982,421
net_rshares83,997,894,224
author_curate_reward""
vote details (1)