Bad Variable Name Error Shell Script
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more bad variable name read about Stack Overflow the company Business Learn more about hiring developers or posting ads shell script dynamic variable name with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow
Shell Script Concatenate Variable Name
is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up “bad variable name” in bash script started by cron up vote 2 down
Shell Script Variable Assignment
vote favorite Works just fine when running it manually on the shell but when I setup a cronjob to run it on reboot I get "bad variable name". #! /bin/sh # /etc/init.d/duplicityCleanUp export PASSPHRASE=foo duplicity remove-older-than 30D --force --gio smb://remote/archiv/ duplicity remove-all-but-n-full 1 --force --gio smb://remote/archiv/ unset PASSPHRASE bash cron share|improve this question asked Oct 8 '14 at 7:23 4485670 422627 #! /bin/sh has a wrong space. shell script variables in string It should be #!/bin/sh. –fedorqui Oct 8 '14 at 9:37 1 @fedorqui I thought the space was wrong too, but apparently it is acceptable... stackoverflow.com/questions/10197690/perl-shebang-space –Mark Setchell Oct 8 '14 at 11:00 1 @MarkSetchell interesting! I learn things every day in this site. Very good to know. –fedorqui Oct 8 '14 at 11:39 add a comment| 1 Answer 1 active oldest votes up vote 5 down vote accepted There is a space between the #! and the /bin/sh. I don't think this is the reported problem but it needs fixing I guess that you are using a version of Unix or Linux where /bin/sh is not bash so the export syntax is wrong. Alter your script to say PASSPHRASE=foo export PASSPHRASE See this answer unix export command share|improve this answer answered Oct 8 '14 at 8:57 Vorsprung 13.1k21232 you may check with: "ls -lrt /bin/sh" to see whether it is really pointing to bash –user1729564 Feb 11 at 9:38 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this
Bash Shell Script Variables
site About Us Learn more about Stack Overflow the company Business Learn more unix shell script variables about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x korn shell script variables Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up “bad variable http://stackoverflow.com/questions/26251272/bad-variable-name-in-bash-script-started-by-cron name” using “read var” up vote 1 down vote favorite 1 I am getting confused about Linux shells. It may be that I oversee something obvious as a Linux noob. All I want is the following script to run: #!/bin/bash echo "Type some Text:" read var echo "You entered: "$var Here is the situation: Installed Ubuntu Server 14.04 in a VirtualBox on windows Installed it http://stackoverflow.com/questions/33320452/bad-variable-name-using-read-var with this packages A SAMBA mounted on /media/buff The script is on /media/buff/ShellScript/test.sh made executable by "sudo chmod a+x /media/buff/ShellScript/test.sh" The rest is default I am using PSPad on windows to edit the script file I read about the dash but I'm not getting it. Here are some variations: Using sh to launch user@Ubuntu:/media/buff/ShellScript$ sh test.sh Type some Text: :bad variable nameread var You entered: Using bash to launch: user@Ubuntu:/media/buff/ShellScript$ bash test.sh Type some Text: ': Ist kein gültiger Bezeichner.var (means no valid identifyier) You entered: Changed the Shebang in the script to "#!/bin/sh", Using sh to launch user@Ubuntu:/media/buff/ShellScript$ sh test.sh Type some Text: :bad variable nameread var You entered: I searched across the Internet for hours now and I assume, that the script itself is ok, but there are missing some environment settings. I used "sudo dpkg-reconfigure dash" to set dash as default shell (which I think is ubuntu default anyway) sadface panda :) bash variables ubuntu server share|improve this question edited Nov 10 '15 at 16:47 Charles Duffy 94.5k15102142 asked Oct 24 '15 at 16:24 VapoRizer 276 1 BTW, if you read the bash tag wiki, this wo
a less extensive syntax. Share this:TwitterFacebookGoogleLike this:Like Loading... Linux Installation Technical Post navigation Previous .deb package installation Next Python - Basics Leave a Reply Cancel reply Enter your comment https://anukulverma.wordpress.com/2015/12/30/shell-script-bad-variable-name-or-unexpected-operator-error/ here... Fill in your details below or click an icon to log in: Email (required) (Address never made public) Name (required) Website You are commenting using your WordPress.com account. (LogOut/Change) You are commenting https://bugs.launchpad.net/bugs/139097 using your Twitter account. (LogOut/Change) You are commenting using your Facebook account. (LogOut/Change) You are commenting using your Google+ account. (LogOut/Change) Cancel Connecting to %s Notify me of new comments via email. Search shell script for: Recent Posts Update Android version (Unofficial) - Cyanogenmod (12-Lollipop13-Marshmallow) Install Custom Recovery (TWRP / CWM) on Android Mobile(Samsung) Mobile Phone (Android) - Root your device / Enable USB debugging / Enable Developermode apt-get install error: Media change: please insert the disclabeled How to retain dns nameserver over reboot (/etc/resolv.conf getsoverwritten) Recent Comments unixODBC sample C Pr… on SQLite3ODBC installationAnukul Verma on unixODBC sample CProgramBlair shell script variable Elzinga on unixODBC sample CProgramInstall Custom Recov… on Mobile Phone (Android) -…Anukul Verma on configure: error: Missing libs… Archives October 2016 September 2016 August 2016 July 2016 June 2016 May 2016 April 2016 March 2016 February 2016 January 2016 December 2015 Categories C General Info Linux Installation Linux Programming Mail Mobile Phone netconf Python SDN Shell Scripting Songs SQL SQLite Technical Tutorials Ubuntu Virtual Machine Meta Register Log in Entries RSS Comments RSS WordPress.com Search for: Recent Posts Update Android version (Unofficial) - Cyanogenmod (12-Lollipop13-Marshmallow) Install Custom Recovery (TWRP / CWM) on Android Mobile(Samsung) Mobile Phone (Android) - Root your device / Enable USB debugging / Enable Developermode apt-get install error: Media change: please insert the disclabeled How to retain dns nameserver over reboot (/etc/resolv.conf getsoverwritten) Recent Comments unixODBC sample C Pr… on SQLite3ODBC installationAnukul Verma on unixODBC sample CProgramBlair Elzinga on unixODBC sample CProgramInstall Custom Recov… on Mobile Phone (Android) -…Anukul Verma on configure: error: Missing libs… Archives October 2016 September 2016 August 2016 July 2016 June 2016 May 2016 April 2016 March 2016 February 2016 January 2016 December 2015 Categories C General Info Linux Installation Linux Programming Mail Mobile Phone netconf Python
Status Importance Assigned to Milestone dash (Ubuntu) Edit Confirmed Low Unassigned Edit You need to log in to change this bug's status. Affecting: dash (Ubuntu) Filed here by: Ian! D. Allen When: 2007-09-12 Confirmed: 2008-02-06 Target Distribution Baltix BOSS Juju Charms Collection Elbuntu Guadalinex Guadalinex Edu Kiwi Linux nUbuntu PLD Linux Tilix tuXlab Ubuntu Ubuntu Linaro Evaluation Build Ubuntu RTM Package (Find…) Project (Find…) Status Importance Confirmed Low Assigned to Nobody Me Comment on this change (optional) Email me about changes to this bug report Also affects project (?) Also affects distribution/package Nominate for series Bug Description
Binary package hint: dash [Edited May 2010] True for all dash up to at least May 2010. Bug in variable expansion (incorrect word-splitting) using an assignment with "local", "readonly", or "export in dash: $ x='1 2 3' $ y=$x # this works fine $ echo "$y" 1 2 3 $ local y=$x # this fails due to dash bug local: 2: bad variable name $ echo "$y" 1 $ readonly y=$x # this fails due to dash bug readonly: 2: bad variable name $ export y=$x # this fails due to dash bug export: 2: bad variable name The same use of assignment using "local", "readonly" and "export" all work fine in bash: bash-3.2$ x='1 2 3' bash-3.2$ y=$x bash-3.2$ echo "$y" 1 2 3 bash-3.2$ local y=$x bash: local: can only be used in a function bash-3.2$ foo () { > local y=$x > echo "$y" > } bash-3.2$ foo 1 2 3 bash-3.2$ readonly y=$x # works fine bash-3.2$ export y=$x # works fine See original description Add tags Tag help Ian! D. Allen (idallen) on 2007-09-12 description: updated description: updated Ian! D. Allen (idallen) wrote on 2007-09-12: #1 Hey! The bugs.launchpad.net bug display web page compresses whitespace. Don't do that. I put the whitespace there to make it more readable. Bugs should be displayed in fixed-width font with all whitespace preserved. Matthias Klose (doko) on 2008-02-06 Changed in dash: importance: Undecided → Low status: New → Confirmed Paul Smith (psmith-gnu) wrote on 2008-04-15: #2 This is not a bug. "local" is a bash-specific feature which is not defined in the POSIX standard for sh (the POSIX shell). If you want to run scripts that require bash-specific features, then you should change them to use #!/bin/bash at the top; by using #!/bin/sh you are agreeing that your shell script uses POSIX-compliant features only and will run with a POSIX standard shell. Cheers! Ian! D. Allen (idallen) wrote on 2008-04-15: #3 An undefined fe