zsh alias with function throwing parse error near - zsh

I have set a simple function in my .zshrc, but its throwing error
zsh: parse error near `()'
function _(){ cd "$1"; }
I am calling it like this _()

Related

How to call the function

I am trying to invoke a function from command prompt, but I am not finding the correct way to invoke it.
This is my script:
echo "Hello World!"
test {
echo "Sample message"
}
I tried below ways:
sh-4.2$ main.sh test
Hello World!
./main.sh: line 5: usuage: command not found
A helpful message!
./main.sh: line 8: syntax error near unexpected token `}'
./main.sh: line 8: `}'
sh-4.2$ . main.sh test
Hello World!
sh: usuage: command not found
A helpful message!
sh: ./main.sh: line 8: syntax error near unexpected token `}'
sh: ./main.sh: line 8: `}'
sh-4.2$ . main.sh test()
sh: syntax error near unexpected token `('
Can you please help me in this.
Couple of issues here, the syntax for test function is wrong, you need have the parentheses around,
test() {
echo "Sample message"
}
export -f test
The export -f syntax allows you to export your functions to the shell; to run them from the command-line you need to source the script in the current shell as,
$ . ./main.sh
Hello World!
Now you can call the function test directly from the command line after having exported it from the script,
$ test
Sample message
Also a good practice to NOT have functions name test, because it is same name a shell built-in. Recommend using some custom names for that.

Unexpected '[', expecting ')' in Symfony console file

This is a strange one, I have never come across it before - but then I've not used Symfony 3.1, only 2.8.
When I run a console command such as clear:cache or a doctrine:schema:update, I get the following error on terminal:
PHP Parse error: syntax error, unexpected '[', expecting ')' in
/var/www/vhosts/mycrmsitetest.co.uk/httpdocs/bin/console on line 20
The line its referring to in the console file is:
$env = $input->getParameterOption(['--env', '-e'], getenv('SYMFONY_ENV') ?: 'dev');
This is exactly the same as on my local drive, but it works there - it's only when it's on the server that this fails.
Does anyone know what this may be?
You need PHP version greater then 5.4. Your script contains the new array syntax ('[]' instead of 'array()'): http://php.net/manual/en/migration54.new-features.php

Convert DOC to PDF using unoconv via Symfony Component

I'm trying to convert word documents to PDF, via the commandline using unoconv via PHP.
I'm using the Symfony Process Component to run the command via the command line.
public function run()
{
$cmd = 'unoconv --listener & unoconv ' . $this->path;
//Tested this to check for permissions and this worked.
//$cmd = 'touch /vagrant/public/testfile.pdf';
$process = new Process($cmd);
$process->run();
return $process->getOutput();
}
This yields no output, and doesn't convert the file. However if I echo the $cmd and paste it into the CLI it converts the file as expected and logs output as it goes.
Any ideas what could be the problem?
Edit:
I've since tried: calling mustRun() & start() methods on the symfony class.
mustRun() gives the following error:
"The command '//command//' failed. Exit Code: 251(Unknown error) Output: ================ Error Output: ================
After adding the log code as suggested by Diego Ferri, I get Error: Unable to connect or start own listener. Aborting. in the log file; but I can't find much online that's helpful for that.
Please read this section but also check the troubleshooting section.
It is possible that the shell is missing some important environment variables for unoconv/LibreOffice to work properly (PATH, HOME, ...). And it is recommended you call the LibreOffice python binary with unoconv instead of leaving it up to unoconv to determine the location of LibreOffice and python.

Typeset not found error in ksh

I have written a statement like typeset -l target_tbl. I am getting an error that typeset : not found.
I ran the same statement on prompt. It executed successfully. I am getting this error in script. Can anyone guide me?
Thanks!

unable to execute unix script using . script_name

I am unable to execute following command in unix as
e.g. ->
export ENVFILE=$PARENT_DIR/../env/.tpms.evr
while i try to execute . "${ENVFILE}" it shows me error as bash: 39910-: command not found
can anybody let me know about how to fix this.
You most probably have a line in .tpms.evr script which bash tries to execute as a command called "39910-"
Please share this .tpms.evr script or just that line containing "39910-"

Resources