Welcome to the Linux Foundation Forum!

script!!!

Posts: 1
edited November 2012 in Command Line/Scripting

hi guys!

i'm newbie and i've got a porblem here... i want to use a function instead of a command, such as using "a" to replace for "who" command ( except using "alias" ).. so i have this script

. ./a.sh

[root@ftp ~]# cat a.sh

#!/bin/bash

function a {

unset a

echo " $a=$(who) "

}

But the result is

a

=root :0 2012-11-28 08:36

root pts/1 2012-11-28 08:36 0.0)

i wanna remove "=" in result, pliz tell me how to do that... thanks for helping me

Comments

  • Posts: 647
    1. "unset a

    This is clearing the "a" variable
    1. echo " $a=$(who) "

    This is echoing to the terminal the expansion of the "a" variable (which you just cleared a line above!) as well as a "=" sign followed by the output of the "who" command.

    What you are trying to do is:
    1. unset a
    2. a="$(who)"
    3. echo "$a"

    However, why don't you just do:
    1. function a { who }

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training