OSX, bash, cat with <<MARKER executing commands


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting OSX, bash, cat with <<MARKER executing commands
# 1  
Old 01-31-2013
Question OSX, bash, cat with <<MARKER executing commands

I have a script that writes another script with

Code:
cat >/usr/local/bin/myscript.sh <<EOF
#!/bin/sh
VAR=`run a command here`
EOF

Problem is, after this is run, I get:

Code:
$ cat /usr/local/bin/myscript.sh
#!/bin/sh
VAR=result of command

How do I stop that from happening with Macs BSDish shell?
# 2  
Old 01-31-2013
To avoid command substitution in a here-document you need to quote at least one character in the delimiter. Try:
Code:
cat >/usr/local/bin/myscript.sh <<"EOF"
#!/bin/sh
VAR=`run a command here`
EOF

# 3  
Old 01-31-2013
Thank you!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Executing bash file with sudo for the second time, leads to permission denied, for some commands

I have a script that checks if the script has been ran with sudo. If the script is not ran as sudo, the current script is being executed with exec sudo bash. You are asked for a password, you type in the password, success. Everything is perfect - the commands inside the script are ran as sudo.... (1 Reply)
Discussion started by: boqsc
1 Replies

2. What is on Your Mind?

OSX 10.14 Mojave Commands - 13K+ Total Man Pages in Repository

Just added OSX 10.14 Mojave Commands (currently over 13K pages in the mojave repo) to our man page repository: OSX 10.14 Mojave Commands We need to update all the man pages to the most current versions, so please contribute man page sets to your favorite OS environment (tar.gz with os and... (3 Replies)
Discussion started by: Neo
3 Replies

3. Programming

Fork and Execvp Not Executing Bash Commands From C correctly.

I had been looking at page 75 of this online book: http://richard.esplins.org/static/downloads/linux_book.pdf I've used the system function in C to call bash commands before, but wanted to learn this way too. The solution in the book worked perfectly. However, I tried changing the simple "ls -l... (3 Replies)
Discussion started by: Azrael
3 Replies

4. Shell Programming and Scripting

Issue in executing cat (remote ssh)

Hi, I need to ssh remotely to a machine and cat a file assign the value to a variable Script: #!/bin/bash -x value=`cat config.txt` echo "$value" ssh me@xxx.host.com "valu='cat /export/home/test.md5'; echo "$valu"" | tee Execution: $ ./x ++ cat config.txt + value='touch me' +... (5 Replies)
Discussion started by: close2jay
5 Replies

5. Shell Programming and Scripting

OSX bash & expect

I have a script that must perform a 'sudo' operation on each of a number of hosts. I'm trying to get expect working so I only have to enter it once, and have run into a couple of issues. First, several examples suggest to use: /usr/bin/expect <<EOD spawn ssh -t $host /usr/bin/sudo -v... (7 Replies)
Discussion started by: jnojr
7 Replies

6. Shell Programming and Scripting

open application with spaces in name [bash][OSX]

Hi guys, I'm new here and new to shell scripting so don't be hard on me I'm trying to create a bash script to restart a process by name in Mac OSX. I have no problem killing the application, the problem comes when launching it again. I managed to store the path in a variable lets say ... (8 Replies)
Discussion started by: jonathanwiesel
8 Replies

7. OS X (Apple)

bash script for dseditgroups in OSX

Hi there, Hope this isn't too complex of a script to try to make but this is what I'm trying to do. Create a new group and add local users that aren't admin to the group. So let's say the new group is 'cats' and 'dog' is the only admin on the machine. Let's say most machines only have one... (4 Replies)
Discussion started by: stop.the.stupid
4 Replies

8. UNIX Desktop Questions & Answers

help with some basic osx terminal commands. fixing permissions on NAS share

I'm hoping someone here can help me. I'm computer literate but by no means an expert! I'm simply trying to recover data from my DLink DNS343 NAS mounted on my X86 iMac using SMB. Somehow, in moving to a new computer, I have lost access to some files on the NAS. Just some files are access denied. ... (0 Replies)
Discussion started by: Quantaa
0 Replies

9. UNIX for Dummies Questions & Answers

Upgrading bash on Darwin (osx)

Hi, I have installed bash 3.2 via darwin ports, however when I try and change the shell i.e. chsh -s /opt/local/bin/bash is says its a non-standard shell? but if i run ./bash i get a new bash prompt with version 3.2? Thanks (3 Replies)
Discussion started by: c19h28O2
3 Replies

10. Shell Programming and Scripting

bash: executing commands and reading exit vals

I have a function that returns a bunch of exit codes, say func1, and in my code I'm trying to execute that function in an if statement. This is the closest I could get. f1call=`func1 $arg1 $arg2` if ]; then ... fi When I run the script the function never gets called. What's the right way... (7 Replies)
Discussion started by: eur0dad
7 Replies
Login or Register to Ask a Question