LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-07-2004, 11:31 AM   #1
irfanhab
Member
 
Registered: Jan 2004
Location: Pakistan
Distribution: OpenSuse 10.2, Slackware 11, Solaris 10
Posts: 415

Rep: Reputation: 34
Bash scripting questions


Hi all,

I have a few bash scripting questions:

How do I return a value from BASH script to a C++ Program?

I have a few problem with this script:

#! /bin/bash
#
# This file creates a swapfile
#
#
# Version: 0.1 07/6/04
#
# Author:
#
echo "Please enter the size of the swapfile (in MB)"
read SIZE
echo "Please Enter the path where the swapfile is to be created along with file name?"
read PATH

dd if=/dev/zero of=$PATH bs=1024 count=$(SIZE*1024)
mkswap $PATH $SIZE
sync
echo "Swap File has been created at $(PATH) of $(SIZE),"
echo "to use swapfile use"
echo " swapon path_to_Swapfile"
echo "to disable"
echo " swapoff path_to_swapfile"
echo "Append an entry to /etc/rc.d/rc.local to automatically enable swapfile at startup"

I get the following errors:
./swapCreate.sh: line 1: SIZE*1024: command not found
./swapCreate.sh: line 15: dd: command not found
./swapCreate.sh: line 16: mkswap: command not found
./swapCreate.sh: line 17: sync: command not found
./swapCreate.sh: line 1: PATH: command not found
./swapCreate.sh: line 1: SIZE: command not found
 
Old 06-07-2004, 11:58 AM   #2
wapcaplet
Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
Not sure, but I think you need double-parentheses around the arithmetic stuff: $((SIZE*1024)). Also, $(PATH) should be just $PATH, $(SIZE) should be just $SIZE.
 
Old 06-07-2004, 12:13 PM   #3
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 34
The other issue: when you exec a process like this, you no may longer have environment variables like PATH.

So, fully qualify each command and define PATH:
Code:
# examples - the paths may not be correct for
# your box 
PATH=".:/home/mydir"
let SIZE=SIZE*1024
/usr/bin/dd if=/dev/zero of=$PATH bs=1024 
/usr/sbin/mkswap $PATH $SIZE
/usr/bin/sync
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash scripting questions stryka Programming 3 11-24-2005 11:46 PM
bash scripting questions nix101 Linux - Newbie 2 09-04-2005 09:26 AM
BASH Scripting akilles Linux - Newbie 5 11-10-2004 07:26 PM
Bash scripting SWAT Linux - Newbie 2 11-11-2003 03:21 AM
About bash scripting pazvant Programming 3 10-20-2003 11:12 AM


All times are GMT -5. The time now is 05:00 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration