I run a command at the command line and it works fine. I have added the same command to a bash script and it cuts the output. I have made sure the quotes are correct and I can't seem to see where I am going wrong.

This is the command when I run it manually:

./ciscocmd -u username -p password -s passwowrd -t -c "show mac address-table address 34e6.xxxx.xxxx"

and it shows

switch#show mac address-table address 34e6.xxxx.xxxx
Mac Address Table

Vlan    Mac Address       Type        Ports
----    -----------       --------    -----
10    34e6.xxxx.xxxx    DYNAMIC     Gi0/2
Total Mac Addresses for this criterion: 1

This is in the script:

portis=`./ciscocmd -u username -p password -s passwowrd -t -c "show mac address-table address 34e6.xxxx.xxxx"`
echo $portis

but yet it outputs this

[root@server]# ./test.sh
switch#ddresses for this criterion: 1--4e6.xxxx.xxxx

I must be missing something. I have tried double "" and '' to surround the mac address but its not working.

Any suggestions?

  1. don't use echo for arbitrary data
  2. quote your variables


printf '%s\n' "$portis"
  1. Avoid `...`. Use $(...) instead.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.