tip: Important tip when writing scripts

Computer builds, hardware and software discussion or troubleshooting, including peripherals. Essentially a general place to talk about desktop computers.
Locked
User avatar
Red Squirrel
Posts: 29209
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

tip: Important tip when writing scripts

Post by Red Squirrel »

When writing a script, or program that processes data, NEVER code in the manipulation part first. Instead make an echo/cout/printf (w/e language you're using :P) statement with the command/variables. First, work on your error checking, and format of the command.

How could this be bad? Take a classmate's script example, it went something like this:

Code: Select all

#!/bin/bash

#todo: error checking

mv $1/* .
[code]


Guess what happens if you just execute the script with no parameters?


Within the end of the period, I managed to restore his system and get it booting up again. 

[color=#888888][size=85]Archived topic from Iceteks,  old topic ID:4676, old post ID:37185[/size][/color]
Honk if you love Jesus, text if you want to meet Him!
Locked