tags:

views:

36

answers:

2

Why is that some commands require the echo statement but others can simply be written without:

#!/bin/bash

aptitude upgrade

echo "mysql-server-5.1 mysql-server/root_password password $DB_PASSWORD" | debconf-set-selections

+1  A: 

The commands that feed on stdin for some input to process, are usually fed by echo command. Echo dumps the string provided to it on stdout, which in turn is duplicated on stdin using the pipe "|". So for the commands which does not require input from stdin or uses some other method of input to process can be written without echo command.

Himanshu
+1  A: 

aptitude upgrade: upgrade is an argument to the aptitude program. If you see output on your screen, it means inside aptitude, its doing some "echoing" to stdout.

programs can also be written to take in stdin through a pipe "|", as in your second case. for example, a program in Python that takes in stdin ,

import fileinput
for line in fileinput.input():
    print line

and to take in arguments

import sys
file = sys.argv[1]

A combination of these 2 will make the program able to take in stdin or an argument. This will be how aptitute or debconf-set-selections is implemented, depending on what language its built on.

ghostdog74