Use asterisk in shell script bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Use asterisk in shell script bash
# 1  
Old 05-24-2009
Use asterisk in shell script bash

Hello,
I am trying to save in a file a single "*" but its not working... look what i am doing...


FILE="/home/teste/a.txt"

...BEGIN...

ASTERISK="*"

echo "STRING $ASTERISK STRING" >> $FILE

...END...

when i do it, the result is a list of all files of the current folder....


i tried to use a "\*", but in the file come "STRING \* STRING"...

i just need a "*" in a variable to save later and stay like that "STRING * STRING"...

thx,
Diogo
# 2  
Old 05-25-2009
Code:
$
$ echo $SHELL
/bin/bash
$
$ ls -1
file1
file2
file3
$
$ FILE="a.txt"
$ ASTERISK="*"
$
$ echo $ASTERISK
file1 file2 file3
$
$ echo "$ASTERISK"
*
$
$ echo "STRING $ASTERISK STRING"
STRING * STRING
$
$ echo "STRING $ASTERISK STRING" >> $FILE
$
$ ls -1
a.txt
file1
file2
file3
$
$ cat $FILE
STRING * STRING
$
$

tyler_durden
# 3  
Old 05-25-2009
if you do echo * it will list the files
if you do echo "*" it will print * so it won't be a problem for you
# 4  
Old 05-25-2009
Which SHELL are you using?
# 5  
Old 05-25-2009
asterisk

I am using shell scrit bash.
I have tested it, but if you try to put this result in a variable and try echo again its will show all files and folders in u current directory.

I used this script to change the crontab file. This is why i used a command with some asterisks grouped.

There is what i have done:

MINUT="0-55"
HOUR="*"
DAYOFMONTH="*"
MONTHOFYEAR="*"
DAYOFWEEK="*"
COMMAND="/home/$(whoami)/file.sh"

FULLCOMMAND="$MINUT $HOUR $DAYOFMONTH $MONTHOFYEAR $DAYOFWEEK $COMMAND"

i think is ok atm, but when i come with the next code the problem begin

echo $FULLCOMMAND >> $TEMPFILE
crontab $TEMPFILE

This code is similar of the original one without irrelevant parts of the problem

thx,
Diogo

i think i found the problem. Like everybody said, i need to use "" to pass the asterisk

i need to change the column that pass the string to file. Like that:


echo $FULLCOMMAND >> $TEMPFILE

to


echo "$FULLCOMMAND" >> $TEMPFILE

i ll try and back with the result.
thx everyone,
Diogo
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed ? Is there any way to get the script names for the process command ? --- Post updated at 08:39 AM --- in KSH (Korn Shell), my command output shows the script names but when run in the Bash Shell... (3 Replies)
Discussion started by: i4ismail
3 Replies

2. Shell Programming and Scripting

Different behavior between bash shell and bash script for cmd

So I'm trying to pass certain json elements as env vars and use them later on in a script. Sample json: JSON='{ "Element1": "file-123456", "Element2": "Name, of, company written in, a very weird way", "Element3": "path/to/some/file.txt", }' (part of the) script: for s... (5 Replies)
Discussion started by: da1
5 Replies

3. Shell Programming and Scripting

Print asterisk instead of password (Bash)

OS : RHEL 6.5 Shell : Bash With the following bash shell script, when I enter password, it won't be printed in the screen. But, I would like Asterisk character to be printed instead of the real characters. Any idea how ? $ cat pass.sh echo "Enter the username" read username echo... (3 Replies)
Discussion started by: John K
3 Replies

4. Shell Programming and Scripting

Shell script - Asterisk logs report

Dear all, I start to build script(s) for few tasks, and I'll use log files to complete the following: 1) when ringnoanswer for a particular operator hits count 10 for waittime > 14000 send mail alert with summary of calls 2) per queue - exitwithtimout > 1 in any hour, then send mail... (12 Replies)
Discussion started by: bigbrobg
12 Replies

5. Shell Programming and Scripting

Bash shell script to check if script itself is running

hi guys we've had nagios spewing false alarm (for the umpteenth time) and finally the customer had enough so they're starting to question nagios. we had the check interval increased from 5 minutes to 2 minutes, but that's just temporary solution. I'm thinking of implementing a script on the... (8 Replies)
Discussion started by: hedkandi
8 Replies

6. Shell Programming and Scripting

Using asterisk as a regular symbol in expect script

Hi there. I wrote an expect script to restart nimbus service on multiple solaris 10 boxes, but following code part is not working for me send "svcadm restart nimbus && sleep 1\r" send "svcs nimbus |awk '/nimbus/ {print \$1}'\r" expect { "online*" {sleep 2;... (3 Replies)
Discussion started by: urello
3 Replies

7. UNIX for Dummies Questions & Answers

space-asterisk in bash killed my server

So, here's the deal... I was attempting to type this: > grep -R "searchterm" * and somehow I typed this instead: > grep -R "searchterm" > * I accidentally typed "space-asterisk" on the second prompt. This apparently caused Bash to attempt to run the first file in the pwd, which... (1 Reply)
Discussion started by: treesloth
1 Replies

8. Shell Programming and Scripting

how to pass variables from Asterisk to a C-script

Hi!I'm trying to write a script in C that Asterisk must call: I would to pass to the script a number digited by the user, make some elaboration with it and then pass the result to Asterisk. I don't understand the mechanism used by Asterisk to pass variable to/from a script: I know that variables... (1 Reply)
Discussion started by: lucio82
1 Replies

9. Shell Programming and Scripting

passing asterisk to a script as variable

I'm writing a script that will ssh to a number of hosts and run commands. I'm a bit stumped at the moment as some of the commands that I need to run contain wildcards (i.e. *), and so far I have not figured out how to escape the * character so the script doesn't expand it. More specifically, here's... (9 Replies)
Discussion started by: GKnight
9 Replies
Login or Register to Ask a Question