Questions tagged [automatic-variable]

18 questions
8
votes
2 answers

Functional differences between $PSScriptRoot and $MyInvocation

Problem I am working with Jenkins to deploy PowerShell scripts remotely. As such, I am trying to figure out if there will be problems utilizing $PSScriptRoot over $MyInvocation.MyCommand.Path for getting the current scripts root directory. Details A…
Brandon
  • 731
  • 2
  • 12
  • 29
4
votes
3 answers

Why can't I use $_ in write-host?

I am trying to pipe an array of strings to write-host and explicitly use $_ to write those strings: 'foo', 'bar', 'baz' | write-host $_ However, it fails with: The input object cannot be bound to any parameters for the command either because the…
René Nyffenegger
  • 39,402
  • 33
  • 158
  • 293
4
votes
2 answers

How does echo $? work?

I am writing some PowerShell scripts to do some build automation. I found here that echo $? returns true or false depending on previous statement. I just found that echo is alias for Write-Output. Write-Host $? also works. But I am still not clear…
VivekDev
  • 20,868
  • 27
  • 132
  • 202
4
votes
2 answers

How to invoke a powershell scriptblock with $_ automatic variable

What works - Lets say I have a scriptblock which I use with Select-Object cmdlet. $jobTypeSelector = ` { if ($_.Type -eq "Foo") { "Bar" } elseif ($_.Data -match "-Action ([a-zA-Z]+)") { …
Vikas Gupta
  • 4,455
  • 1
  • 20
  • 40
3
votes
2 answers

Passing arguments as array to PowerShell function

I'm trying to figure out how I can pass multiple strings as an array to a powershell function. function ArrayCount([string[]] $args) { Write-Host $args.Count } ArrayCount "1" "2" "3" ArrayCount "1","2","3" ArrayCount…
Tom Deseyn
  • 1,735
  • 3
  • 17
  • 29
3
votes
1 answer

Are global variables in C automatic variables?

I was studying ANSI C programming language and it says in introduction: "Local variables are typically "automatic," or created anew with each invocation." I'm guessing allocating and deallocating variables work with stack frame logic of Java. So…
Michael
  • 577
  • 1
  • 11
  • 21
2
votes
1 answer

Equivalent of "&& cd $_" in Powershell

With bash I can create a directory and immediately enter it with mkdir mydir && cd $_. Is there a powershell equivalent of $_?
Dominik
  • 135
  • 1
  • 7
2
votes
1 answer

What does @$ mean in makefile?

What does @$ mean in the below make recipe ? @$(OBJCOPY) -S --set-section-flags .bss=alloc,contents -O binary $(BINARY).elf $(BINARY).bin Thanks
2
votes
2 answers

Makefiles: specific 'no input files', automatic variables

I'm new to makefiles, and they puzzle me. I have the following folder hierarchy: A folder named lib contains tow folders: include (with file mylib.h) and src (with file mylib.cpp). It also contains a Makefile, which, for some reason, gives me an…
1
vote
1 answer

What does $_ bind to at the top level of pipelines, in Powershell?

In Powershell, a pipeline can contain filters such as ForEach-Object: get-process | %{$_.name} Within the script block of the foreach filter, it's possible to use the $_ auto variable to refer to the current object of the script block. What does…
Dess
  • 2,064
  • 19
  • 35
1
vote
3 answers

Unexpected execution of "all" target in my makefile

I've a makefile that is suppose to repeat an execution of a c code (BootstrapCL.c) one time for each file.csv in the directory. For each execution it should give in input to the c code (as argv) 2 string: the name, with and without extention, of the…
user1172131
  • 103
  • 7
1
vote
1 answer

How to pass parameters to a PS script invoked through Start-Job?

I want to use start-job to run a .ps1 script requiring a parameter. Here's the script file: #Test-Job.ps1 Param ( [Parameter(Mandatory=$True)][String]$input ) $output = "$input to output" return $output and here is how I am running it: $input =…
Ben Adams
  • 129
  • 1
  • 2
  • 11
1
vote
1 answer

Target's directory in prerequisites without second expansion

Lets assume, i want to call make somepath/abc.pot which depends on somepath/somefiles.c My target I've created so far looks like %.pot: $(dir $@)*.c @echo "it works" ifeq (,$(wildcard $@)) # pot-file does not exist, do something else # …
1
vote
1 answer

Can't get different values of dependencies with automatic variable '$<' in makefile

I'm making once which compiles some sort algorithms that i made. I have a structure like this: |/sorting_algorithms |----/bin |----/build |----/include |--------tiempo.h |----/src |--------bubble_sort.c …
Alejandro
  • 15
  • 6
0
votes
1 answer

GNUMake - Using text functions with match pattern as prerequisite

I want to use the match pattern of a Makefile rule in a text function in the perquisites list. Let's say I want to build a file, and that files perquisites are any other files with the same name in a list. list_of_files=a/x b/x a/y b/y c/z %: …
111111
  • 15,686
  • 6
  • 47
  • 62
1
2