Wild char getting expanded in echo


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Wild char getting expanded in echo
# 1  
Old 07-27-2018
Wild char getting expanded in echo

Hi All,
I am having a issue in a script. I am trying to execute a select * from a scirpt to a database and printing the the sql string. The * in the sqltring is printing all the files in the directory. How to handle it ?

Code:
..
..
sql="select * from emp"
execute ($sql)
echo $sql


Here my echo is not giving the sql command it is showing all the files in the directory.
# 2  
Old 07-27-2018
Code:
sql='select * from emp'
execute "$sql"

# 3  
Old 07-27-2018
Quote:
Originally Posted by vgersh99
Code:
sql='select * from emp'
execute "$sql"



The problem is with the echo. The execute $sql work fine. When it echo it expand it and print all file
# 4  
Old 07-27-2018
Quote:
Originally Posted by arunkumar_mca
The problem is with the echo. The execute $sql work fine. When it echo it expand it and print all file
Actually it's the same problem with echo as you had with execute.
Double-quote the argument to the command.
This User Gave Thanks to vgersh99 For This Post:
# 5  
Old 07-27-2018
this is the script . The printlog is called and the sqlcmd print select and all the files name in the log
Code:
_bkp_table_name=processed$_timestamp
  _sqlcmd="select * into $_bkp_table_name from processed"
print_log "\n$_sqlcmd"

print_log() {
       print $1
       print $1 >> $_status_file
}

I also tried this. assume I will get the output as *

Code:
$a="*"
$echo $a

this is listing all files

Last edited by arunkumar_mca; 07-27-2018 at 11:18 AM..
# 6  
Old 07-27-2018
Quote:
Originally Posted by arunkumar_mca
this is the script . The printlog is called and the sqlcmd print select and all the files name in the log
Code:
_bkp_table_name=processed$_timestamp
  _sqlcmd="select * into $_bkp_table_name from processed"
print_log "\n$_sqlcmd"

print_log() {
       print $1
       print $1 >> $_status_file
}

In addition to double-quoting $1 in print_log, I'd enable set -x in the script and in the function call and see what comes out....
This User Gave Thanks to vgersh99 For This Post:
# 7  
Old 07-27-2018
Quote:
Originally Posted by vgersh99
In addition to double-quoting $1 in print_log, I'd enable set -x in the script and in the function call and see what comes out....


Adding quotes in printlog worked. Thanks a lot
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How the home alias (~) is it expanded?

echo $HOME return : /home/user1echo ~ return : /home/user1My_path=~/bin/"some dir1/some dir2" kate "$My_path/some_file"Kate open a file "~/~/bin/some dir1/some dir2/some_file" which does not exists. I was expecting kate to open : "~/bin/some dir1/some dir2/some_file" Any help is welcome. ... (8 Replies)
Discussion started by: jcdole
8 Replies

2. Solaris

zpool hasn't expanded

Hi Guys, I have a raidz zpool that consists of four disks. 2x2TB, 1x1TB and 1x0.75TB. Originally it was only 1x1TB, 3x0.75TB, and I had around 1.7TB of storage capacity. I've just switched out two of the 0.75TB disks for the 2x2TB ones. I did this one at a time and now the resilvering is... (2 Replies)
Discussion started by: rudigarude
2 Replies

3. Programming

error: invalid conversion from ‘const char*’ to ‘char*’

Compiling xpp (The X Printing Panel) on SL6 (RHEL6 essentially): xpp.cxx: In constructor ‘printFiles::printFiles(int, char**, int&)’: xpp.cxx:200: error: invalid conversion from ‘const char*’ to ‘char*’ The same error with all c++ constructors - gcc 4.4.4. If anyone can throw any light on... (8 Replies)
Discussion started by: GSO
8 Replies

4. Solaris

war file not expanded (tomcat solaris)

hi .. my example.war file is not expanded in the webapps folder.. could u guide me why the file is not expanded when i restart tomcat... (1 Reply)
Discussion started by: senkerth
1 Replies

5. Shell Programming and Scripting

List file with variables expanded

Hello, I have this problem. I have script file, e.g. #!/usr/bin/ksh echo $MY_DIR ls -lt $MY_DIR I want to list the script but with MY_DIR variable expanded. E.g. MY_DIR=/abc/xyz (in shell MY_DIR is set) So I want to list the script and see: #!/usr/bin/ksh echo /abc/xyz ls... (6 Replies)
Discussion started by: r1omen
6 Replies

6. UNIX for Advanced & Expert Users

Redirect contained in variable not expanded as expected

Hi all, I have a selection of files that contain several commands that write to a file and are started as background processes similar to below. command_to_run_simulator -simulator_arguments > log_file 2>&1 & command_to_run_simulator -simulator_arguments > log_file 2>&1 &... (2 Replies)
Discussion started by: noose
2 Replies

7. UNIX for Dummies Questions & Answers

wild char * in if

if ; then => is it correct? i need to check 10 files size and do the same action. The file name is same but extension of the files are different. how do i deal with it? Please help (1 Reply)
Discussion started by: nidhink
1 Replies

8. Programming

Adding a single char to a char pointer.

Hello, I'm trying to write a method which will return the extension of a file given the file's name, e.g. test.txt should return txt. I'm using C so am limited to char pointers and arrays. Here is the code as I have it: char* getext(char *file) { char *extension; int i, j;... (5 Replies)
Discussion started by: pallak7
5 Replies

9. Programming

Macros expanded output of c files

Hi, I want to just expand the macros in a set of c files from a filelist which are in different directories. I don't want the header files included in the c file to be expanded. I have a perl script which does gcc -E <infile> -I <path to search for header files> -imacros <infile> But in... (1 Reply)
Discussion started by: spsenthil
1 Replies
Login or Register to Ask a Question