The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
FDISK problems woodson2 Red Hat 2 03-30-2009 10:14 AM
using fdisk seyiisq SUN Solaris 4 11-22-2008 04:17 AM
Using fdisk in scripts Frank_a UNIX for Dummies Questions & Answers 1 02-11-2005 09:46 AM
(c)fdisk and RedHat 7.2 98_1LE UNIX for Dummies Questions & Answers 1 01-17-2002 03:38 AM
I need fdisk that works with dos and unix gparsons70 UNIX for Dummies Questions & Answers 1 10-28-2001 10:29 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-27-2009
latenite latenite is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 13
HEREDOC with fdisk

Hi folks

What I'm trying is to build a partitioning script.
I can pass a HEREDOC to fdisk just fine. Like this:


Code:
fdisk /dev/sda << EOF
p
q
EOF

but I don't know how to put that HEREDOC into a varible to pass it to fdisk.

This is what I have tried so far (no luck)


Code:
#!/bin/bash


HEREDOC_VAR_1=1


HEREDOC_VAR_2=$(cat <<EOF
p
q
EOF
)


HEREDOC_VAR_3=$(cat <<'EOF'
p
p
q
EOF
)

echo $HEREDOC_VAR_1
echo $HEREDOC_VAR_2
echo $HEREDOC_VAR_3

fdisk /dev/sda << $HEREDOC_VAR_2

echo "this works somehow but gets multiple p from former variables..."

fdisk /dev/sda << EOF
p
q
EOF

ANY Help is greatly appreciated....my head hurts from this...I just can not figure it out.
  #2 (permalink)  
Old 09-27-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,972
Try this:
Code:
#!/bin/bash


HEREDOC_VAR_1=1


HEREDOC_VAR_2='p
q
'


HEREDOC_VAR_3='p
p
q
'

echo $HEREDOC_VAR_1
echo $HEREDOC_VAR_2
echo $HEREDOC_VAR_3

echo "$HEREDOC_VAR_2" | fdisk /dev/sda

  #3 (permalink)  
Old 09-27-2009
latenite latenite is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 13
MAN thank you. That workzz

Still curious! Is there a way to do it with a variable that holds this "kind" (heredoc) syntax?

Code:
<<EOF
p
q
EOF

  #4 (permalink)  
Old 09-27-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,972
I don't think so. The HEREDOCs are interpreted by the shell as the information that is to be sent through stdin to a process. It doesn't survive parameter expansion.
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:56 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0