Sponsored Content
Operating Systems OS X (Apple) Creating An Executable On The Fly... Post 302898214 by sea on Sunday 20th of April 2014 01:42:05 PM
Old 04-20-2014
Having (a little) time in the train, trying to make it multi functional:

Code:
#!/bin/bash
#	Compile file from arg
#	Extension of: https://www.unix.com/os-x-apple-/246397-creating-executable-fly-post302898214.html
#
#	Variables
#
	src=/tmp/example.c				# Set default src file as example
#
#	Action
#
	if [ -z $1 ]					# No arg (codefile) is passed
	then 	touch $src				# Create empty file
		echo '/* Embed a C script and compile on the fly. */
#include<stdio.h>
main()
{
    printf("A simple text line as a test...\n");
}' 		> $src					# Redirect it to default src file
	else	# Check if it is in current path or somewhere else
		[ -f "$(pwd)/$1" ] && \
			src="./$1" || src="$1"		# Set var 'src' to passed argument
	fi
	out="${src/.c$/}"				# Remove '.c' extension for the outputfile
	echo -e "Compiling \"${src##*/}\" to $out..."		
	gcc "$src" -o "$out" || exit 1			# If build fails exit with failure  -- doesnt work  with 'spaced' path names :(
	"$out"						# Execute it, `"` if passed subfolders contain spaces
	exit 0						# Return successfully

Now edited at home on windows, took more time to write on the phone than expected... + copy-paste is a pain.
Going to try now (as if i had written all on the phone), gotta reboot to linux first though. Smilie

Have fun Smilie

EDIT:
Script fixed now, saved as ~./local/bin/compile with execution flag set, it outputs as:
Beeing aware, no compile arguments would be passed as of now, thats up to you to change/add if desired.
Code:
[sea@P50 ~]$ compile
Compiling "example.c" to /tmp/example...
A simple text line as a test...
[sea@P50 ~]$ compile example2.c
Compiling "example2.c" to ./example2...
Just another test...
[sea@P50 ~]$


Last edited by sea; 04-20-2014 at 05:15 PM..
 

10 More Discussions You Might Find Interesting

1. Programming

problem in creating executable for a client program

Hi, I am trying to run simple client server c program in unix.At the compling stage server is creating an executable but the client is not. below is the link to the source codes: http://www.cs.rpi.edu/courses/sysprog/sockets/server.c http://www.cs.rpi.edu/courses/sysprog/sockets/client.c ... (2 Replies)
Discussion started by: konas
2 Replies

2. UNIX for Dummies Questions & Answers

mv and compress on the fly

I want to move and compress a big export file. Like mv file_exp /filesystem/file_exp |compress The file system is too small to compress and move with 2 steps. What is the best command for me. I'm running solaris. :confused: (1 Reply)
Discussion started by: simquest
1 Replies

3. UNIX for Dummies Questions & Answers

creating executable for every C file

hello Folks, once we compile any C code on Linux, we run the code using "./a.out".. but can we have an executable for every program so that we can run the code directly without compiling the code every time. just run the executable and get the output! Thanks! (7 Replies)
Discussion started by: compbug
7 Replies

4. OS X (Apple)

What's The Easiest Route To Creating A Unix Executable File for Terminal?

I've seen the executable open in the application OmniOutliner, can I create an executable with this app? I'd like to be able to create the unix executable and insert it into terminal, but I'm not sure if the Omni app will allow me to create it. Any one have any ideas or possibly familiar with... (10 Replies)
Discussion started by: unimachead
10 Replies

5. Solaris

Disable IPMP on the fly

Wats would be the best way to disable link based IPMP on the fly without loosing network connectivity ? (6 Replies)
Discussion started by: fugitive
6 Replies

6. What is on Your Mind?

The Only Way To Fly !

This is great! Lqh8e2KYIrU (8 Replies)
Discussion started by: Neo
8 Replies

7. UNIX Desktop Questions & Answers

creating an executable file from shell scripts

Hi Friends, I have a shell script which does some operations etc, would it be possible to create an executable file out from this shell script? meaning the executable file is not editable, thus the source code will not be visible to other users for copyright reasons. Please help, thanks! (1 Reply)
Discussion started by: kokoro
1 Replies

8. Shell Programming and Scripting

Creating executable script--please help

Hi group, I am very beginner in shell scripting and self learning. I am trying to create and executable script to run awk from user defined variables. e.g. suppose from a given file I want to delete some rows or some columns We need to repeat this process for many files. Thus I was... (4 Replies)
Discussion started by: smitra
4 Replies

9. HP-UX

Compress dbexport on the fly

Hi, I have an old HPUX 10.20 server running Informix 7.23 I need to dump the database to get it off that hardware before it dies. Unfortunately there is insufficient local diskspace to do so. I have set up a linux box with sufficient disk onto which I can export the database. Having... (1 Reply)
Discussion started by: fella
1 Replies

10. Shell Programming and Scripting

Execute script on the fly

Hi all, I am calling a zsh script from batch file . This zsh just removes the trigger file in a particular directory.File name is passed as a parameter from the batch file Problem is this batch is called in multiple other batch files and sometimes system says file cant be used as it is used... (4 Replies)
Discussion started by: Hypesslearner
4 Replies
mlib_ImageErode4(3MLIB) 				    mediaLib Library Functions					   mlib_ImageErode4(3MLIB)

NAME
mlib_ImageErode4 - four neighbor erode SYNOPSIS
cc [ flag... ] file... -lmlib [ library... ] #include <mlib.h> mlib_status mlib_ImageErode4(mlib_image *dst, const mlib_image *src); DESCRIPTION
The mlib_ImageErode4() function performs an erode operation on an image by using each pixel's four orthogonal neighbors. The source and destination images must be single-channel images. The data type can be MLIB_BIT, MLIB_SHORT, MLIB_USHORT, or MLIB_INT. For 4-neighbor binary images, it uses the following equation: dst[x][y][0] = AND{ src[x][y][0], src[x-1][y][0], src[x+1][y][0], src[x][y-1][0], src[x][y+1][0] } For 4-neighbor grayscale images, it uses the following equation: dst[x][y][0] = MIN{ src[x][y][0], src[x-1][y][0], src[x+1][y][0], src[x][y-1][0], src[x][y+1][0] } where x = 1, ..., w-2; y = 1, ..., h-2. PARAMETERS
The function takes the following arguments: dst Pointer to destination image. src Pointer to source image. RETURN VALUES
The function returns MLIB_SUCCESS if successful. Otherwise it returns MLIB_FAILURE. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
mlib_ImageErode4_Fp(3MLIB), mlib_ImageErode8(3MLIB), mlib_ImageErode8_Fp(3MLIB), attributes(5) SunOS 5.10 10 Nov 2004 mlib_ImageErode4(3MLIB)
All times are GMT -4. The time now is 05:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy