0

I have both scripts:

#!/bin/bash
#this is scpt1.bash

echo -n "Enter name: "
read name

function $name

#!/bin/bash
#this is scpt2.bash

function() {
     ARG1=$1
     mysql -u <username> -e "
     use <Database Name>;
     insert into <Table Name> (column1) values ("$ARG1"); "
}

Enter name: magic mic

Error: 1054 (42S2): Unknown Column 'magic" in 'field list'


upon debugging..... bash -x scpt1.bash

I found out that the variable in ARG1="magic" and it is not "magic mic"

I also did function "$name" but it is also an error

is there a simple way for this?

Lynchburg
  • 1
  • 1
  • You have to quote your variables: `function "$name"`. [ShellCheck](https://shellcheck.net) will automatically point this out. – that other guy Oct 28 '20 at 19:18
  • I installed ShellCheck in my ubuntu but still it would give me a result of a list of options on mysql command. – Lynchburg Oct 28 '20 at 19:28
  • ARG1 should be the right value now. Did you also escape the quoting in `values ("$ARG1"); "` into `values (\"$ARG1\"); "` (or since mysql can use single quotes, `values ('$ARG1'); "`)? – that other guy Oct 28 '20 at 20:34
  • Thank you so much :) it worked where it should be like this: function "$name" and '$ARG1' – Lynchburg Oct 29 '20 at 03:10

0 Answers0