Help with Bash quoting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with Bash quoting
# 1  
Old 06-06-2014
Linux Help with Bash quoting

I am trying to write a BASH script that will prompt a user to enter a number of days, then calculate the date.

My problem is the date command uses single or double quotes. For Example..
Code:
 date -d "7 days"

Here is an example of some same code I am trying to work through.

Code:
echo "when do you want the sudo access to expire?"
read num_days
echo "so we want sudo access to expire on"     date -d "$num_days days"

How would I write this code to ask for the number of days then calculate the future days with the correct quoting?
# 2  
Old 06-06-2014
The single or double quoting is not the problem, you seem to have a handle on it.

The problem is that the shell's not going to convert date -d ... into a string unless you ask it to.

Code:
echo "so we want sudo access to expire on $(date -d "$num_days days")"

The $( ) syntax will do so nicely. It even nests inside other "" quite unlike the old ` ` syntax.
# 3  
Old 06-06-2014
Welcome to forums,

Try


Code:
echo "so we want sudo access to expire on"     $(date -d "$num_days days")

--edit--

I see corona already posted answer
# 4  
Old 06-06-2014
Linux

Thanks,

I'm almost there. So how would I go about storing
Code:
$(date -d "$num_days days")"

as a variable to call back at a later time? I can't seem to get this work by using
Code:
SUDO_EXPIRE=(date -d "$num_days days")

Bruce

Last edited by javajockey; 06-06-2014 at 05:25 PM.. Reason: mistake
# 5  
Old 06-06-2014
It works exactly the way we showed you.

Code:
SUDO_EXPIRE=$(date -d "$num_days days")

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Tricky BASH quoting question

I have some data files that I can identify by a certain pattern in the names using find. Every one of those data files has an XML file associated with it (can be multiple data files per XML file). The XML file is always up one directory from the data file(s) in a folder calledRun##### -... (12 Replies)
Discussion started by: Michael Stora
12 Replies

2. Shell Programming and Scripting

Quoting the values in second field

Hi, I have got a file comp_data containing the below data : 38232836|9302392|49 39203827|8203203,3933203|52 72832788|567,3245,2434324|100 This file can have many rows like shown above. I want the values separated by "," in second column(taking "|" as delimiter) to be in quotes. These... (2 Replies)
Discussion started by: msabhi
2 Replies

3. Shell Programming and Scripting

Quoting / interface question

Hi, My first shell script is one that prints the five largest directories in a given directory. My current effort is as follows, it gives me the output I'd like, but I have to quote a globbed pathname, which seems wrong: #!/bin/sh du -hs $1 | sort -rn | head -n 5 And I must invoke... (2 Replies)
Discussion started by: aardymir
2 Replies

4. Shell Programming and Scripting

bash: correct quoting with find and exiv2?

Hi, I need to embed a metatag to image files which contain qrcodes, i usually do this with exiv -M "set Exif.Image.DocumentName `zbarimg -q -Sdisable -Sqrcode.enable --raw image.tif`" image.tif which works fine. However I need to do this recursivly for whole directory and subdiretory... (4 Replies)
Discussion started by: mcframe
4 Replies

5. Shell Programming and Scripting

Quoting issue: Trouble with bash strings in script

I can do this on the command line: sqsh -S 192.168.x.x -o tmp -U user -P fakepass -D horizon -C "\ select second_id from borrower where btype like '%wsd%' " I can also just leave the SQL at the end intact on one line .... ... However, when I throw this in a script like: $SQSH -o... (4 Replies)
Discussion started by: Bubnoff
4 Replies

6. Shell Programming and Scripting

Quoting Characters

I have this data how do i add ' ' to them like '-AAL00L' , '-BBE4577' , 'ABC' -AAL00L -BBE4577 ABC (5 Replies)
Discussion started by: dinjo_jo
5 Replies

7. Shell Programming and Scripting

quoting question

hi guys, i have a question related to quoting but i am not sure how to formulate it... lets say we want to simulate the following shell actions cd ~/project-dir ctags /home/work/folder1/*.sh /home/work/folder2/*.sh /home/work/folder3/*.sh so i make the following script buidtags.sh ... (2 Replies)
Discussion started by: aegis
2 Replies

8. Shell Programming and Scripting

BASH quoting behavior

The block below isn't a surprise:$ ls file1 file2 file3 $ x=* $ echo $x file1 file2 file3 $ echo '$x' $x $ echo "$x" * $But I found this block a bit bewildering:$ echo $x' >' * $I'm wondering why substitution wasn't performed on the $x, since it was unquoted (as far as I can tell).... (5 Replies)
Discussion started by: na5m
5 Replies

9. UNIX for Dummies Questions & Answers

Quoting of special characters

Hello, I am getting very confused as to where should i quote special/metacharacters in shell. Sometimes i write * directly and it works, othertimes i have to do "*". Same is the case with other special characters like /,\,.,$,etc. Can somebody give me link to somewhere where i can found... (1 Reply)
Discussion started by: vibhor_agarwali
1 Replies

10. UNIX for Dummies Questions & Answers

Wildcards and quoting

Hi All In a script, I want a user to enter 4 characters, these can be a mix of letters (uppercase and lowercase) and numbers. In this example $var represents what the user has entered. eg $var can be A9xZ, 3DDL, bbHp .........etc I need to check that the user has only entered characters... (2 Replies)
Discussion started by: Bab00shka
2 Replies
Login or Register to Ask a Question