0

For testing purpose, I need to set up Linux command alias like this:

alias 'dmidecode -t 1'='cat ~/test/system_info'

But the alias command doesn't work like this. It seems that the alias name should be continuous characters without space. Any thought on how to achieve this? Thanks a lot and really appreciate your help!

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
dibugger
  • 546
  • 1
  • 7
  • 21

1 Answers1

3

Write a dmidecode() function that defers to the regular dmidecode if its arguments aren't exactly -t 1. command suppresses function lookup.

dmidecode() {
    if [[ $1 == -t && $2 == 1 ]]; then
        cat ~/test/system_info
    else
        command dmidecode "$@"
    fi
}
John Kugelman
  • 349,597
  • 67
  • 533
  • 578