473,698 Members | 2,221 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Finding out the active Unix shell

Hi,

It's seems that csh and tcsh acts a bit different when handling
special characters in quotes.
i.e: if i'll supply my program with the following arguments: -winpath
"c:\\temp\\ "
tcsh will take it as -winpath "c:\temp\"
and csh will take it literally (with the double-slashes).

Is there a way for me to know what shell is currently running my
program, so I could fit a different code for each shell ?

Jun 7 '07 #1
21 3015
On 7 Jun, 08:22, Tom Gur <gur....@gmail. comwrote:
Hi,

It's seems that csh and tcsh acts a bit different when handling
special characters in quotes.
i.e: if i'll supply my program with the following arguments: -winpath
"c:\\temp\\ "
tcsh will take it as -winpath "c:\temp\"
and csh will take it literally (with the double-slashes).

Is there a way for me to know what shell is currently running my
program, so I could fit a different code for each shell ?
Not in the C language per se.

I suggest you ask the question in comp.unix.progr ammer.

Jun 7 '07 #2
"Tom Gur" <gu*****@gmail. comschrieb im Newsbeitrag
news:11******** **************@ o5g2000hsb.goog legroups.com...
Hi,

It's seems that csh and tcsh acts a bit different when handling
special characters in quotes.
i.e: if i'll supply my program with the following arguments: -winpath
"c:\\temp\\ "
tcsh will take it as -winpath "c:\temp\"
and csh will take it literally (with the double-slashes).

Is there a way for me to know what shell is currently running my
program, so I could fit a different code for each shell ?
What has this got to do with C and why do you post this question in
comp.lang.c?

the environment variable $SHELL might help. But you may also check in
comp.unix.progr ammer

Bye, Jojo
Jun 7 '07 #3
Tom Gur <gu*****@gmail. comwrites:
It's seems that csh and tcsh acts a bit different when handling
special characters in quotes.
[snip]

Ask in comp.unix.shell .

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 7 '07 #4
Maybe I wasn't clear.
I'm writing a C program (a server) that runs a Java program (an agent)
with some arguments.
The agent's shell is unknown, so I need to check, within my C code
what kind of shell runs on the account that runs the agent.
I was wondering whether you know any kind of function that can get
environment variables - so I'll be able to check the value of $SHELL
in the agent's machine.

Thanks

Jun 7 '07 #5
On 7 Jun, 10:07, Tom Gur <gur....@gmail. comwrote:
Maybe I wasn't clear.
Or maybe you weren't listening.
I'm writing a C program (a server) that runs a Java program (an agent)
with some arguments.
The agent's shell is unknown, so I need to check, within my C code
what kind of shell runs on the account that runs the agent.
I was wondering whether you know any kind of function that can get
environment variables - so I'll be able to check the value of $SHELL
in the agent's machine.
In the C language as such there won't be any such thing.

In the Unix APIs there may be an appropriate function but that's not
in the remit of this group.

You'll get better answers in a group relating to Unix - most likely
comp.unix.progr ammer.

<OffTopic>
Unix has getenv() but the $SHELL variable does not seem to be altered
if a new shell is launched.

And as to why anyone would use C shells, I despair...
</OffTopic>

Jun 7 '07 #6
In article <11************ *********@q75g2 000hsh.googlegr oups.com>,
Tom Gur <gu*****@gmail. comwrote:
>Maybe I wasn't clear.
I'm writing a C program (a server) that runs a Java program (an agent)
with some arguments.
The agent's shell is unknown, so I need to check, within my C code
what kind of shell runs on the account that runs the agent.
You're still not very clear. How are you running the program?
>I was wondering whether you know any kind of function that can get
environment variables - so I'll be able to check the value of $SHELL
in the agent's machine.
You can use the C function getenv(), but since you talk about "the
agent's machine" and "the account that runs the agent" it sounds
as if testing an environment variable in the server isn't going to
do much good. Perhaps you could have the server run a small program
on the other machine that does 'getenv("SHELL" )'.

-- Richard
--
"Considerat ion shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Jun 7 '07 #7
ma**********@po box.com wrote:
On 7 Jun, 10:07, Tom Gur <gur....@gmail. comwrote:
I was wondering whether you know any kind of function that can get
environment variables - so I'll be able to check the value of $SHELL
in the agent's machine.

In the C language as such there won't be any such thing.
Yesno.
In the Unix APIs there may be an appropriate function but that's not
in the remit of this group.

You'll get better answers in a group relating to Unix - most likely
comp.unix.progr ammer.

<OffTopic>
Not yet.
Unix has getenv()
Actually, that's an ISO C function, but...
but the $SHELL variable does not seem to be altered if a new shell is launched.
....C makes no guarantees about which variables are available, let alone
what they mean.

So the OP could easily use a C function, but _how_ he should use this
function does depend on the OS he uses (and frustratingly, could even
depend on the shell he uses... so to find out which shell he has, he
first has to find out which shell he has. Nice.)

Richard
Jun 7 '07 #8
ma**********@po box.com wrote, On 07/06/07 10:20:
On 7 Jun, 10:07, Tom Gur <gur....@gmail. comwrote:
>Maybe I wasn't clear.

Or maybe you weren't listening.
>I'm writing a C program (a server) that runs a Java program (an agent)
with some arguments.
The agent's shell is unknown, so I need to check, within my C code
what kind of shell runs on the account that runs the agent.
>I was wondering whether you know any kind of function that can get
environment variables - so I'll be able to check the value of $SHELL
in the agent's machine.

In the C language as such there won't be any such thing.

In the Unix APIs there may be an appropriate function but that's not
in the remit of this group.

You'll get better answers in a group relating to Unix - most likely
comp.unix.progr ammer.

<OffTopic>
Unix has getenv() but the $SHELL variable does not seem to be altered
if a new shell is launched.
getenv is actually part of the C standard, so the ability to use it to
access environment variable is topical here. However, what environment
variables are available and what they do is not topical, so you are
correct that comp.unix.progr ammer is a better place for the OP to ask.
And as to why anyone would use C shells, I despair...
</OffTopic>
Possibly because they like them :-)
--
Flash Gordon
Jun 7 '07 #9
On Thu, 07 Jun 2007 09:07:54 -0000, in comp.lang.c , Tom Gur
<gu*****@gmail. comwrote:
>Maybe I wasn't clear.
I'm writing a C program (a server) that runs a Java program (an agent)
with some arguments.
The agent's shell is unknown, so I need to check, within my C code
what kind of shell runs on the account that runs the agent.
The answer is unfortunatly still the same. You need to ask the
specialists in your os and /or compiler, since C itself has no
facilities for doing this. Most probably there's a function called
getenv() or something similar provided by your platform.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Jun 7 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5663
by: Mohsin | last post by:
Hi all, I have a perl program which makes a user exit to the O/S (unix, solaris) to issue a O/S command. I know that the shell it invokes is NOT a korn shell, because I captured the shell info into a file with a 'ps' command. My question is "How to explicitly specify a Korn shell to be used by perl?" Eg of my perl code: ## Begin code snippet..
22
2673
by: Tony Houghton | last post by:
I'm using pygame to write a game called Bombz which needs to save some data in a directory associated with it. In Unix/Linux I'd probably use "~/.bombz", in Windows something like "C:\Documents And Settings\<user>\Applicacation Data\Bombz". There are plenty of messages in the archives for this group about how to find the correct location in Windows, but what about Mac OS? There I don't know the correct location for this sort of thing at...
7
3542
by: kamkwokho | last post by:
Could any answer following questions as many as you can. ii) Write a C shell script convertmin which will read in a number, thought of as representing minutes, and print out the number of hours/minutes it represents so: $ convertmin Enter a number of minutes: 128
22
3063
by: Ryan M | last post by:
I've been programming for a while, but most of my experience is on unix. How do C compilers work on operating systems that weren't written in C? And that have no libc? Compiling C on unix seems so easy. Everything in the code either goes right to machine code, or links to a C library (often libc) or links to the kernel. Are there libc equivalents on non-unix OSes? -- Using M2, Opera's revolutionary e-mail client:...
46
2524
by: dawn | last post by:
Hi all, I am now working on a C program under Unix. The requirement for the program is that: A file name is passed to program as a parameter. The program will Find files under a specified directory. The matched file must have the same content with the given file. It does not matter whether the filenames are the same. It is easy to find file that has the same name with given file, but may be hard to find the files that with the same...
0
3052
by: Aashif | last post by:
I want to call Unix Shell script which is available in other Server (Unix server) from windows application using C#. Currently the shell script runs the C program but the GUI is not good, So I want to create GUI in C# windows application and call that C program using Shell script so first I have to call unix shell script from C#. Please guide me friends.
9
78332
by: sohan | last post by:
Hi, I want to know how to connect and execute a db2 query from inside a UNIX shell script. Details: We have a unix shell script. We need to execute multiple db2 sql queries from this shell script and export the result to a file. Any code snippet on this will be helpful.
2
1590
by: frikk | last post by:
Hey everyone, (Sorry about the first message if it made it - i got cut off early). I have a homework problem for my Operating Systems class. I am supposed to use a command such as "ps -aux" and return "N number of users, M number of processes". How am I to go about doing this? I am not very familiar with string parsing in c++, is this the only way? I am talking about getting the output from "ps -aux" and parsing it to retrieve the...
2
2691
by: zw | last post by:
Hi I have 2 unix boxes. In each box, I have a unix shell script that captures certain statistics to a file of the unix box. During the run of the 2 shell scripts, I need a common timestamp for both. I'm thinking of writing a C# app to issue commands every few mins to these shell scripts and capture the statistics back to a file in a Windows folder. The C# app will provide the common timestamp for the statistics retrieved from the unix...
0
8668
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9152
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9014
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7708
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4612
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2320
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.