[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: cope with spaces in an environment variable
From: |
Masahiro Yamada |
Subject: |
Re: cope with spaces in an environment variable |
Date: |
Mon, 19 Jun 2023 12:09:35 +0900 |
On Mon, Jun 19, 2023 at 4:22 AM Kerin Millar <kfm@plushkava.net> wrote:
>
> On Mon, 19 Jun 2023 03:37:24 +0900
> Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> > Hi.
> >
> > I'd like to know the proper handling of an environment variable
> > when the value may contain spaces (with quoting).
> >
> > Here is my question.
> >
> > You have the environment variable 'CC', which contains a compiler path.
> >
> > For example, how to write a shell script to
> > compile a C file with ${CC}?
>
> By shell script, do you mean that POSX sh is the intended target?
Thanks for the pointers, all guys.
Ideally, working on POSIX sh would be nice.
So, what I learnt from the link David referenced
and hints from Alex,
[1] With bash extension:
#!/usr/bin/bash
declare -a "cc_command=( ${CC} )"
"${cc_command[@]}" foo.c
"${cc_command[@]}" bar.c
"${cc_command[@]}" baz.c
[2] With POSIX sh
#!/bin/sh
eval set -- "${CC}"
"$@" foo.c
"$@" bar.c
"$@" baz.c
Of course, the latter cannot preserve
the original positional parameters, though.
--
Best Regards
Masahiro Yamada
- cope with spaces in an environment variable, Masahiro Yamada, 2023/06/18
- Re: cope with spaces in an environment variable, Davide Brini, 2023/06/18
- Re: cope with spaces in an environment variable, alex xmb ratchev, 2023/06/18
- Re: cope with spaces in an environment variable, Lawrence Velázquez, 2023/06/18
- Re: cope with spaces in an environment variable, Kerin Millar, 2023/06/18
- Re: cope with spaces in an environment variable,
Masahiro Yamada <=
- Re: cope with spaces in an environment variable, Greg Wooledge, 2023/06/18
- Re: cope with spaces in an environment variable, Jeffrey Walton, 2023/06/19
- Re: cope with spaces in an environment variable, Greg Wooledge, 2023/06/19
- Re: cope with spaces in an environment variable, Kerin Millar, 2023/06/19
- Re: cope with spaces in an environment variable, Kerin Millar, 2023/06/19